PHPackages                             mubat/yii2-inherit-model-behavior - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. mubat/yii2-inherit-model-behavior

ActiveYii2-extension[Database &amp; ORM](/categories/database)

mubat/yii2-inherit-model-behavior
=================================

yii2 behavior to connect inherit ActiveRecord

v1.3.2(7y ago)35721MITPHPPHP &gt;=5.6

Since May 14Pushed 7y ago1 watchersCompare

[ Source](https://github.com/mubat/yii2-inherit-model-behavior)[ Packagist](https://packagist.org/packages/mubat/yii2-inherit-model-behavior)[ RSS](/packages/mubat-yii2-inherit-model-behavior/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (6)Dependencies (1)Versions (7)Used By (0)

yii2-inherit-model-behavior
===========================

[](#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',
]
```

You can disable inherit object deletion if need.

Installation
------------

[](#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-examples)

- Options:

    - **`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:

```
    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']);
    }
```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity62

Established project with proven stability

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

6

Last Release

2905d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d3436efa1b9fc8454415f0955f0f27b24751f7434f53b9a5fcdc49367bff3d3e?d=identicon)[mubat](/maintainers/mubat)

---

Tags

modelyii2Behaviorinherit

### Embed Badge

![Health badge](/badges/mubat-yii2-inherit-model-behavior/health.svg)

```
[![Health](https://phpackages.com/badges/mubat-yii2-inherit-model-behavior/health.svg)](https://phpackages.com/packages/mubat-yii2-inherit-model-behavior)
```

###  Alternatives

[voskobovich/yii2-linker-behavior

This behavior makes it easy to maintain many-to-many and one-to-many relations in your ActiveRecord models.

80319.0k9](/packages/voskobovich-yii2-linker-behavior)[sjaakp/yii2-sortable-behavior

Sort ActiveRecords and related records in Yii2.

36144.7k](/packages/sjaakp-yii2-sortable-behavior)[nanson/yii2-postgis

Yii2-extension to work with postgis data

1851.6k](/packages/nanson-yii2-postgis)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
