fgh151/yii2-postgresql-array-field

Yii2 postgresql jsonb field support behavior

Maintainers

Package info

github.com/fgh151/yii2-postgresql-array-field

pkg:composer/fgh151/yii2-postgresql-array-field

Statistics

Installs: 89

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.0.2 2026-06-17 11:00 UTC

This package is auto-updated.

Last update: 2026-06-17 11:00:58 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": "*"
	}
}

Upgrade from 1.* to 2.*

breaking changes

  • min php version 8.2
  • fgh151\PostgresqlJsonb\models\DynamicModel is deprecated, and was deleted.
  • fgh151\PostgresqlJsonb\PostgresqlJsonbFieldBehavior::postgresqlJsonDecode now return array
  • use value as array, instead of object (see example below)

Db 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';