Yii Framework Forum: JSON Data Type Support for PostgreSQL - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

JSON Data Type Support for PostgreSQL Rate Topic: -----

#1 User is offline   pkbhadkoliya 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 09-June 14

Posted 18 February 2015 - 05:10 AM

Hello,

I am using yii2 with PostgreSQL 9.4 version. In my database schema, my chain table looks like:

CREATE TABLE chain (
id BIGINT NOT NULL DEFAULT nextval('chain_id_seq') PRIMARY KEY,
name VARCHAR(80) NOT NULL UNIQUE,
contacts JSONB, -- contacts: [array { name, number, email }]
notes TEXT,
created_at INT,
updated_at INT
);

I have Chain class extending ActiveRecord, with properties as follow:

* @property integer $id
* @property string $name
* @property string $data
* @property string $contacts
* @property string $notes
* @property integer $created_at
* @property integer $updated_at

My question is if I want to use array php type for $contacts which is automatically converted into JSON string while storing into db, and back to array when fetch from db.

How can I do that?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users