PHPackages                             dd174/yii2-related-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. dd174/yii2-related-behavior

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

dd174/yii2-related-behavior
===========================

v1.0.3(9y ago)07.7k1[2 issues](https://github.com/DD174/yii2-related-behavior/issues)BSD-3-ClausePHP

Since Feb 15Pushed 9y ago1 watchersCompare

[ Source](https://github.com/DD174/yii2-related-behavior)[ Packagist](https://packagist.org/packages/dd174/yii2-related-behavior)[ RSS](/packages/dd174-yii2-related-behavior/feed)WikiDiscussions master Synced 2mo ago

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

Yii2 Related behavior for Yii 2
===============================

[](#yii2-related-behavior-for-yii-2)

Обновляет (создает/изменяет/удаляет) связи модели

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer require dd174/yii2-related-behavior

```

Usage
-----

[](#usage)

in Model behavior

```
    public function behaviors()
    {
        return array_merge(
            parent::behaviors(),
            [
                ...
                [
                    'class' => RelatedBehavior::class,
                    'relations' => ['relatedName'],
                    // optional:
                    'scenarios' => ['relatedName' => ['create' => 'create', 'update' => 'update']],
                ],

```

in Controller

```
$model->loadRelation('relatedName', Yii::$app->request->post(), 'keyPost');

```

Tips
----

[](#tips)

in related Model unique formName

```
private $formName;

/**
 * @param null $unique необходим для получения доступа к файлам ($_FILES) в новой моделе
 */
public function setFormName($unique = null)
{
	$unique = $unique ?: ($this->primaryKey ?: uniqid('new', true));
	$this->formName = parent::formName() . '[' . $unique . ']';
}

/**
 * Составляем свое name, что бы легко использовать на одной странице форму с несколькими экземплярами этой модели
 * @return string
 */
public function formName()
{
	if (!$this->formName) {
		$this->setFormName();
	}

	return $this->formName;
}

```

Credits
-------

[](#credits)

Author: Danil DD

Email:

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~82 days

Total

4

Last Release

3493d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/179673a06deb8454ec0dffe1d6ef15046f4b2988c560cba377adec1bfdedf17d?d=identicon)[DD174](/maintainers/DD174)

---

Top Contributors

[![DD174](https://avatars.githubusercontent.com/u/2971088?v=4)](https://github.com/DD174 "DD174 (10 commits)")

---

Tags

yii2Behavioractiverecordrelated

### Embed Badge

![Health badge](/badges/dd174-yii2-related-behavior/health.svg)

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

###  Alternatives

[sjaakp/yii2-taggable

Manage tags of ActiveRecord in Yii2.

3030.6k](/packages/sjaakp-yii2-taggable)[mdmsoft/yii2-autonumber

Auto number extension for the Yii framework

1830.9k](/packages/mdmsoft-yii2-autonumber)[baibaratsky/yii2-serialized-attributes-behavior

Yii2 Serialized Attributes Behavior

1174.1k9](/packages/baibaratsky-yii2-serialized-attributes-behavior)[asinfotrack/yii2-audittrail

Yii2-audittrail is a behavior and a set of widgets to track all modifications performed on a model

1727.0k](/packages/asinfotrack-yii2-audittrail)

PHPackages © 2026

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