2017 © Pedro Peláez
 

yii2-extension yii2-inherit-model-behavior

yii2 behavior to connect inherit ActiveRecord

image

mubat/yii2-inherit-model-behavior

yii2 behavior to connect inherit ActiveRecord

  • Thursday, May 31, 2018
  • by mubat
  • Repository
  • 1 Watchers
  • 3 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 7 Versions
  • 150 % Grown

The README.md

yii2-inherit-model-behavior

Use this behavior to connect inherit ActiveRecord with (one-to-many relation), (*1)

In parent ActiveRecord should be column that uses to store ID of inherit ActiveRecord., (*2)

Extension supports 2 request formats:, (*3)

  • default Yii2 input data, like:
//$_POST[]
[
    'Object' => [
        'option_1' => 'value',
        'option_2' => 'another value',
    ]
]
  • simple input names (usable for API), like:
//$_POST[]
[
    'option_1' => 'value',
    'option_2' => 'another value',
]

You can disable inherit object deletion if need., (*4)

Installation

The preferred way to install this extension is through Composer., (*5)

Either run php composer.phar require mubat/yii2-inherit-model-behavior "~1.0", (*6)

or add "mubat/yii2-inherit-model-behavior": "~1.0" to the require section of your composer.json, (*7)

Usage examples

  • Options:, (*8)

    • dependClass [required string] - target class name;
    • dependClassInitConfig [array] - some init configuration for target class. See \yii\app\Yii::createObject()
    • virtualOption [required string] - option name that will be use at project
    • relationMethod [string] - getter that returns with \yii\db\ActiveQuery object. By default, get[virtualOption]()
    • primaryKeyName [string] - key name at inherit model. Default "id"
    • linkAttribute [string] - column name in owner table for connect with inherit table. By default, [virtualOption]_id
    • createDependObjectOnEmpty [boolean] - you can disable empty inherit object creation if need. By default, true
    • simpleRequest [boolean] - How need to parse simple options: like 'bar' (_true_) or like 'Foo[bar]' (_false_) at request. By default, false
    • deleteWithOwner - with this option you can disable/enable run delete() action on inherit object. _Default: true_ (It also can change status during processing on the fly)
  • Usage:, (*9)

    public function behaviors()
    {
        $behaviors = parent::behaviors();
        $behaviors['image'] = [
            'class' => InheritModelBehavior::class,
            'dependClass' => Image::class, //required
            'virtualOption' => 'image', //required
            'linkAttribute' => 'image_id',
            'relationMethod' => 'getSavedImage',
            'simpleRequest' => true,
            'deleteWithOwner' => true,
        ];
        return $behaviors;
    }

    /** @return \yii\db\ActiveQuery */
    public function getSavedImage()
    {
        return $this->hasOne(Image::class, ['id' => 'image_id']);
    }

The Versions

31/05 2018

dev-master

9999999-dev

yii2 behavior to connect inherit ActiveRecord

  Sources   Download

MIT

The Requires

 

by Oleg Sergienko

yii2 model behavior inherit

31/05 2018

v1.3.2

1.3.2.0

yii2 behavior to connect inherit ActiveRecord

  Sources   Download

MIT

The Requires

 

by Oleg Sergienko

yii2 model behavior inherit

31/05 2018

v1.3.1

1.3.1.0

yii2 behavior to connect inherit ActiveRecord

  Sources   Download

MIT

The Requires

 

by Oleg Sergienko

yii2 model behavior inherit

30/05 2018

v1.3

1.3.0.0

yii2 behavior to connect inherit ActiveRecord

  Sources   Download

MIT

The Requires

 

by Oleg Sergienko

yii2 model behavior inherit

15/05 2018

v1.2

1.2.0.0

yii2 behavior to connect inherit ActiveRecord

  Sources   Download

MIT

The Requires

 

by Oleg Sergienko

yii2 model behavior inherit

15/05 2018

v1.1

1.1.0.0

yii2 behavior to connect inherit ActiveRecord

  Sources   Download

MIT

The Requires

 

by Oleg Sergienko

yii2 model behavior inherit

14/05 2018

v1.0

1.0.0.0

yii2 behavior to connect inherit ActiveRecord

  Sources   Download

MIT

The Requires

 

by Oleg Sergienko

yii2 model behavior inherit