xakki / yii2-ar-json
ActiveRecord json field
v0.2
2019-02-05 01:51 UTC
Requires
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2026-03-01 00:26:58 UTC
README
Combine some field into json field ActiveRecord
composer require xakki/yii2-ar-json
This table has only field - id, create, option
The option is a json filed (for PostgreSQL is a jsonb)
/** * Example class * @property integer $id * @property string $create * @property string $text * @property array $data */ class Example extends \xakki\yii2-ar-json\components\ActiveRecordJson { protected $_json_attribute = 'option'; protected $_json_catch = ['text', 'data', 'info']; public static function tableName() { return '{{example}}'; } /** * For new record only */ public function setAttributeDefault() { $this->text = 'Example text'; $this->data = ['test']; $this->info = 2 } public static function doSomeThing() { $thisData = self::findOne(1); echo $thisData->text; print_r($thisData->data); } }