PHPackages                             consultnn/yii2-mongodb-embedded - 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. consultnn/yii2-mongodb-embedded

ActiveLibrary[Database &amp; ORM](/categories/database)

consultnn/yii2-mongodb-embedded
===============================

Yii2 behaviors implement handling of mongodb embedded documents

v1.0.5(3y ago)124.9k7MITPHP

Since Jul 15Pushed 3y ago17 watchersCompare

[ Source](https://github.com/consultnn/yii2-mongodb-embedded)[ Packagist](https://packagist.org/packages/consultnn/yii2-mongodb-embedded)[ RSS](/packages/consultnn-yii2-mongodb-embedded/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (3)Versions (9)Used By (0)

Yii2 behaviors implement handling of mongodb embedded documents
===============================================================

[](#yii2-behaviors-implement-handling-of-mongodb-embedded-documents)

- Add attribute with name starting with underscore to model.

```
/**
* @inheritdoc
*/
public function attributes()
{
    return [
        '_address',
        '_phones',
    ]
}

```

- Add "safe" validation rule for attribute without underscore in name.

```
/**
 * @inheritdoc
 */
public function rules()
{
    return [
            [['address', 'phones'], 'safe'],
        ]
}

```

- Add behavior with attribute name with underscore in name

```
'address' => [
    'class' => EmbedsOneBehavior::className(),
    'attribute' => '_address',
    'embedded' => Address::className()
],
'phones' => [
    'class' => EmbedsManyBehavior::className(),
    'attribute' => '_phones',
    'embedded' => Phone::className()
],

```

- Your embedded documents must be inherited from [EmbeddedDocument](EmbeddedDocument.php) class.

```
class Phone extends EmbeddedDocument
{
    public $number;
    public $type;

    public function rules()
    {
        return [
            [['number', 'type'], 'string'],
            [['type'], 'in', 'range' => ['home', 'work']],
        ];
    }
}

```

- To create empty embedded document set base document's scenario to the value listed in initEmptyScenarios parameter of EmbedsManyBehavior

```
'address' => [
    'class' => EmbedsOneBehavior::className(),
    'attribute' => '_address',
    'initEmptyScenarios' => ['create', 'update'],
    'embedded' => Address::className()
],

```

- Use attribute without underscore in form or view

```
// Address
echo $form->field($company->address, 'detail');
echo $form->field($company->address, 'id')->hiddenInput();

// Phones
foreach($company->phones as $key => $phone) {
    echo $form->field($phone, 'number');
    echo $form->field($phone, 'type');
}

```

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 62.7% 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 ~559 days

Recently: every ~699 days

Total

6

Last Release

1209d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6559f1e755ff5770d012bdedb22e589553caabaf3a78eadfa944d832ce16eef2?d=identicon)[sokrat](/maintainers/sokrat)

---

Top Contributors

[![sokrat](https://avatars.githubusercontent.com/u/427543?v=4)](https://github.com/sokrat "sokrat (32 commits)")[![serieznyi](https://avatars.githubusercontent.com/u/2323142?v=4)](https://github.com/serieznyi "serieznyi (7 commits)")[![marfarin](https://avatars.githubusercontent.com/u/7046093?v=4)](https://github.com/marfarin "marfarin (4 commits)")[![Synida](https://avatars.githubusercontent.com/u/14039463?v=4)](https://github.com/Synida "Synida (3 commits)")[![smirnov-e](https://avatars.githubusercontent.com/u/131781557?v=4)](https://github.com/smirnov-e "smirnov-e (2 commits)")[![mreuro1987-afk](https://avatars.githubusercontent.com/u/234199061?v=4)](https://github.com/mreuro1987-afk "mreuro1987-afk (1 commits)")[![lav45](https://avatars.githubusercontent.com/u/675367?v=4)](https://github.com/lav45 "lav45 (1 commits)")[![batyrmastyr](https://avatars.githubusercontent.com/u/9303221?v=4)](https://github.com/batyrmastyr "batyrmastyr (1 commits)")

---

Tags

embedded-documentsyii2yii2-behaviors

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/consultnn-yii2-mongodb-embedded/health.svg)

```
[![Health](https://phpackages.com/badges/consultnn-yii2-mongodb-embedded/health.svg)](https://phpackages.com/packages/consultnn-yii2-mongodb-embedded)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[bizley/migration

Migration generator for Yii 2.

296389.5k11](/packages/bizley-migration)[yii2tech/illuminate

Yii2 to Laravel Migration Package

11416.2k](/packages/yii2tech-illuminate)[mootensai/yii2-relation-trait

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

49232.7k9](/packages/mootensai-yii2-relation-trait)

PHPackages © 2026

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