Skip to content

Commit

Permalink
update README.md
Browse files Browse the repository at this point in the history
added UPGRADE.md.

prepare to version 2.0.
  • Loading branch information
chemezov committed May 20, 2022
1 parent 6a53d6a commit 75255e6
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ If you want to use other types than string you can use ```AttributeTypecastBehav

```php
use chemezov\yii2_dynamic_fields\DynamicFieldsBehavior;
use yii\behaviors\AttributeTypecastBehavior;

class User extends \yii\db\ActiveRecord
{
Expand Down Expand Up @@ -122,6 +123,7 @@ So you can use this behavior. Here example of User model:

```php
use chemezov\yii2_dynamic_fields\DynamicFieldsBehavior;
use yii\behaviors\AttributeTypecastBehavior;

/**
* Class User
Expand Down Expand Up @@ -183,3 +185,53 @@ class User extends \yii\db\ActiveRecord
}
}
```

Usage for JsonDynamicFieldsBehavior
-----------------------------------

Using this behavior is very similar to using it with the `DynamicFieldsBehavior`. This behavior store dynamic fields in separate column of model table in json.

You should create a column in your model table, e.g. `additional_data`, with type `text`, and allow `null` value. Example for migration:

```php
$this->addColumn('your_table', 'additional_data', $this->text()->null());
```

```php
use chemezov\yii2_dynamic_fields\JsonDynamicFieldsBehavior;
use yii\behaviors\AttributeTypecastBehavior;

class User extends \yii\db\ActiveRecord
{
public function behaviors()
{
return [
'dynamicFields' => [
'class' => JsonDynamicFieldsBehavior::class,
'fields' => ['my_boolean_attribute'],
],
'typecast' => [
'class' => AttributeTypecastBehavior::class,
'attributeTypes' => [
'my_boolean_attribute' => AttributeTypecastBehavior::TYPE_BOOLEAN,
],
'typecastAfterFind' => true,
],
];
}

public function rules() {
return [
[['my_boolean_attribute'], 'default', 'value' => null],
[['my_boolean_attribute'], 'boolean'],
];
}

public function attributeLabels()
{
return [
'my_boolean_attribute' => 'My boolean attribute',
];
}
}
```
9 changes: 9 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Upgrade from 1.2. to 2.0.

- Renamed methods:

`loadDynamicFieldsValues` > `loadDynamicFields`
`saveDynamicFieldsValues` > `saveDynamicFields`
`deleteDynamicFieldsValues` > `deleteDynamicFields`

- Added `JsonDynamicFieldsBehavior` to store dynamic fields in separate model attribute in json.

0 comments on commit 75255e6

Please sign in to comment.