fgh151/yii2-postgresql-array-field

Yii2 postgresql jsonb 字段支持行为

v0.0.1 2016-10-07 11:34 UTC

This package is auto-updated.

Last update: 2024-08-28 22:24:55 UTC


README

Yii2 postgresql 对象字段支持行为

================

为 yii2 模型提供 PostgreSQL 对象字段支持。

安装

将依赖项添加到项目的 composer.json 文件中

{
	"require": {
		"fgh151/yii2-postgresql-array-field": "*"
	}
}

迁移示例

$this->createTable('UserReward', [
    'jsonField' => fgh151\PostgresqlJsonb\db\Schema::TYPE_JSONB
]);

使用示例

将行为附加到模型的一个或多个字段上

use yii\db\ActiveRecord;
use \fgh151\PostgresqlJsonb\PostgresqlJsonbFieldBehavior;

/**
 * @property array $modelField
 */
class Model extends ActiveRecord{
	public function behaviors() {
		return [
			[
				'class' => PostgresqlJsonbFieldBehavior::className(),
				'arrayFieldName' => 'modelField', // model's field to attach behavior
				'onEmptySaveNull' => true // if set to false, empty array will be saved as empty PostreSQL array '{}' (default: true)
			]
		];
	}
}
$model->jsonField->property = 'value';
$model->jsonField->otherProperty->otherPropertyValue = 'another value';