fgh151 / yii2-postgresql-array-field
Yii2 postgresql jsonb field support behavior
Installs: 87
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/fgh151/yii2-postgresql-array-field
Requires
- php: >=5.4.0
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2025-09-29 00:25:34 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';