xakki / yii2-ar-json
ActiveRecord json字段
v0.2
2019-02-05 01:51 UTC
Requires
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-08-29 05:18:27 UTC
README
将一些字段合并到json字段ActiveRecord
composer require xakki/yii2-ar-json
此表仅包含字段 - id
、create
、option
。其中option
是一个json字段(对于PostgreSQL是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); } }