mubat/yii2-inherit-model-behavior yii2 behavior to connect inherit ActiveRecord

behaviormodelinherit

yii2-inherit-model-behavior

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

In parent ActiveRecord should be column that uses to store ID of inherit ActiveRecord.

Extension supports 2 request formats:

  • 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',
    ]

Installation

The preferred way to install this extension is through Composer.

Either run php composer.phar require mubat/yii2-inherit-model-behavior "~1.0"

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

Usage examples

  • Usage:

    public function behaviors()
    {
        $behaviors = parent::behaviors();
        $behaviors['image'] = [
            'class' => InheritModelBehavior::class,
            'dependClass' => Image::class, //required
            'virtualOption' => 'image', //required
            'linkAttribute' => 'image_id',
            'relationMethod' => 'savedImage',
            'simpleRequest' => true,
        ];
        return $behaviors;
    }
    
    /** @return \yii\db\ActiveQuery */
    public function getSavedImage()
    {
        return $this->hasOne(Image::class, ['id' => 'image_id']);
    }

Statistics

Downloads
GitHub Stars
GitHub Forks

Releases

Comments



v1.2 is the latest of 3 releases



MIT license
Stats
2 github stars & 0 github forks
0 downloads in the last day
0 downloads in the last 30 days
0 total downloads