PHPackages                             solutosoft/yii-linkmany - 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. solutosoft/yii-linkmany

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

solutosoft/yii-linkmany
=======================

Load, validate and save automatically related Active Record models

1.2.0(1y ago)42.3kBSD-3-ClausePHPCI passing

Since Sep 30Pushed 1y ago1 watchersCompare

[ Source](https://github.com/solutosoft/yii-linkmany)[ Packagist](https://packagist.org/packages/solutosoft/yii-linkmany)[ Docs](https://github.com/solutosoft/yii-linkmany)[ RSS](/packages/solutosoft-yii-linkmany/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (2)Versions (9)Used By (0)

Yii LinkMany
============

[](#yii-linkmany)

Load, validate and save automatically `hasMany` relations.

[![Build Status](https://github.com/solutosoft/yii-linkmany/actions/workflows/tests.yml/badge.svg)](https://github.com/solutosoft/yii-linkmany/actions)[![Total Downloads](https://camo.githubusercontent.com/da65aeb969d9207ba8bc916621a77383ea0ca1ef518c0a7076fabacdbb3f3bac/68747470733a2f2f706f7365722e707567782e6f72672f736f6c75746f736f66742f7969692d6c696e6b6d616e792f646f776e6c6f6164732e706e67)](https://packagist.org/packages/solutosoft/yii-linkmany)[![Latest Stable Version](https://camo.githubusercontent.com/42de109bbfe683452d242212790f8478904c79809ec0ecfbc191215e017a78db/68747470733a2f2f706f7365722e707567782e6f72672f736f6c75746f736f66742f7969692d6c696e6b6d616e792f762f737461626c652e706e67)](https://packagist.org/packages/solutosoft/yii-linkmany)

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

[](#installation)

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

Either run

```
php composer.phar require --prefer-dist solutosoft/yii-linkmany

```

or add

```
"solutosoft/yii-linkmany": "*"
```

to the require section of your composer.json.

Usage
-----

[](#usage)

This extension provides support for ActiveRecord `hasMany` relation saving. This support is granted via \[\[\\solutosoft\\linkmany\\LinkManyBehavior\]\] ActiveRecord behavior. You'll need to attach it to your ActiveRecord class and point the target "has-many" relation for it:

```
class Post extends ActiveRecord
{
    public function behaviors()
    {
        return [
            'linkManyBehavior' => [
                'class' => LinkManyBehavior::class,
                'relations' => [
                    'tags',
                    'messages' => [
                        'formName'  => 'Post[messages]',
                        'validate' => false,
                        'deleteOnUnlink' => false
                    ]
                ]
            ],
        ];
    }

    public function getMessages()
    {
        return $this->hasMany(Message::class, ['post_id' => 'id']);
    }

    public function getTags()
    {
        return $this->hasMany(Tag::class, ['id' => 'tag_id'])
            ->viaTable('post_tag', ['post_id' => 'id']);
    }
}
```

Being attached \[\[\\solutosoft\\linkmany\\LinkManyBehavior\]\] you can load data using the method \[\[\\solutosoft\\linkmany\\LinkManyBehavior::fill\]\]

```
use yii\web\Controller;

class PostController extends Controller
{
    public function actionCreate()
    {
        $model = new Post();

        /**
         * $_POST could be something like:
         * [
         *     'tags' => [1,2]
         *     'comments' => [
         *         [
         *             'subject' => 'First comment',
         *             'content' => 'This is de fist comment',
         *         ], [
         *             'subject' => 'Second comment',
         *             'content' => 'This is de second comment',
         *         ]
         *     ]
         * ];
         */
        if ($model->fill(Yii::$app->request->post())) {
            $model->save(); // save the model and relations
            return $this->redirect(['view']);
        }

        return $this->render('create', [
            'model' => $model,
        ]);
    }
}
```

Credits
-------

[](#credits)

This Package is inspired by:

- [la-haute-societe/yii2-save-relations-behavior](https://github.com/la-haute-societe/yii2-save-relations-behavior)
- [yii2tech/ar-linkmany](https://github.com/yii2tech/ar-linkmany).

I wanted to have a combination of both. Thanks to both authors.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance46

Moderate activity, may be stable

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

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

Total

8

Last Release

417d ago

### Community

Maintainers

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

---

Top Contributors

[![leandrogehlen](https://avatars.githubusercontent.com/u/1750751?v=4)](https://github.com/leandrogehlen "leandrogehlen (49 commits)")

---

Tags

activerecordhasmanyrelationsrelationshipsyii2yii2-extensionyii2Behavioractive-recordloadrelationfill

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/solutosoft-yii-linkmany/health.svg)

```
[![Health](https://phpackages.com/badges/solutosoft-yii-linkmany/health.svg)](https://phpackages.com/packages/solutosoft-yii-linkmany)
```

###  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)[mootensai/yii2-relation-trait

Yii 2 Models load with relation, &amp; transaction save with relation

47220.3k9](/packages/mootensai-yii2-relation-trait)[voskobovich/yii2-many-many-behavior

This behavior makes it easy to maintain relations many-to-many in the your ActiveRecord model.

112181.9k2](/packages/voskobovich-yii2-many-many-behavior)[arogachev/yii2-tree

Database tree structures management for Yii 2 framework

222.1k](/packages/arogachev-yii2-tree)

PHPackages © 2026

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