fgh151 / yii2-postgresql-array-field
Yii2 postgresql jsonb field support behavior
v0.0.1
2016-10-07 11:34 UTC
Requires
- php: >=5.4.0
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2025-07-29 00:08:18 UTC
README
Yii2 postgresql object field support behavior
================
Provides PostgreSQL object fields support for yii2 models.
Installation
Add a dependency to your project's composer.json:
{
"require": {
"fgh151/yii2-postgresql-array-field": "*"
}
}
Migration example
$this->createTable('UserReward', [
'jsonField' => fgh151\PostgresqlJsonb\db\Schema::TYPE_JSONB
]);
Usage example
Attach behavior to one or more fields of your model
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';