PHPackages                             sorokinmedia/yii2-ar-relations - 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. sorokinmedia/yii2-ar-relations

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

sorokinmedia/yii2-ar-relations
==============================

AR relations for Yii2

1339PHPCI failing

Since Jan 4Pushed 6y ago5 watchersCompare

[ Source](https://github.com/sorokinmedia/yii2-ar-relations)[ Packagist](https://packagist.org/packages/sorokinmedia/yii2-ar-relations)[ RSS](/packages/sorokinmedia-yii2-ar-relations/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

yii2-ar-relations
=================

[](#yii2-ar-relations)

[![Total Downloads](https://camo.githubusercontent.com/0d04f94a8054d8c9d3237e1c7a8a858a352a9c84389a0ff400978f7d9879f40f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736f726f6b696e6d656469612f796969322d61722d72656c6174696f6e732e737667)](https://packagist.org/packages/sorokinmedia/yii2-ar-relations)

---

Sorokin.Media repository

---

[![Total Downloads](https://camo.githubusercontent.com/0d04f94a8054d8c9d3237e1c7a8a858a352a9c84389a0ff400978f7d9879f40f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736f726f6b696e6d656469612f796969322d61722d72656c6174696f6e732e737667)](https://packagist.org/packages/sorokinmedia/yii2-ar-relations)

Расширение базового класса `\yii\db\ActiveRecord`

Позволяет описать метод `initClasses` и использовать в связях (yii2 relations) автоматическую подстановку нужного класса

Необходимо в проекте использовать трейт, где определить в виде атрибуторв все классы, учавствующие в связях и каждому атрибуту присвоить значение - имя нужного класса

Присвоение классов переменным делать в методе `initClasses`

Пример файла трейта:

```
trait RelationClassTrait
{
    public $__userClass;

    public function initClasses()
    {
        $this->__userClass = User::class;
    }

    /**
     * инициализация связей
     */
    public function init()
    {
        parent::init();
        $this->initClasses();
    }

    /**
     * метод для динамической подстановки нужного класса в связь
     * @param string $field
     * @param string $class
     * @return mixed
     */
    public function setRelationClass(string $field, string $class)
    {
        return $this->{$field} = $class;
    }
}

```

Необходимо во всех ActiveRecord моделях использовать данный трейт, а также имплементацию интерфейса `RelationInterface`

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6071315?v=4)[Ruslan Gilyazetdinov](/maintainers/Ma3oBblu)[@Ma3oBblu](https://github.com/Ma3oBblu)

---

Top Contributors

[![Ma3oBblu](https://avatars.githubusercontent.com/u/6071315?v=4)](https://github.com/Ma3oBblu "Ma3oBblu (11 commits)")

### Embed Badge

![Health badge](/badges/sorokinmedia-yii2-ar-relations/health.svg)

```
[![Health](https://phpackages.com/badges/sorokinmedia-yii2-ar-relations/health.svg)](https://phpackages.com/packages/sorokinmedia-yii2-ar-relations)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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