2017 © Pedro Peláez
 

library yii2-mongodb-embedded

Yii2 behaviors implement handling of mongodb embedded documents

image

consultnn/yii2-mongodb-embedded

Yii2 behaviors implement handling of mongodb embedded documents

  • Monday, January 11, 2016
  • by sokrat
  • Repository
  • 13 Watchers
  • 9 Stars
  • 1,520 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 7 Forks
  • 0 Open issues
  • 6 Versions
  • 3 % Grown

The README.md

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

The Versions

11/01 2016

dev-master

9999999-dev

Yii2 behaviors implement handling of mongodb embedded documents

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sergey Sipatov
by ICC

11/01 2016

dev-1-new-major-version

dev-1-new-major-version

Yii2 behaviors implement handling of mongodb embedded documents

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sergey Sipatov
by ICC

11/01 2016

v1.0.3

1.0.3.0

Yii2 behaviors implement handling of mongodb embedded documents

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sergey Sipatov
by ICC

27/07 2015

v1.0.2

1.0.2.0

Yii2 behaviors implement handling of mongodb embedded documents

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sergey Sipatov
by ICC

15/07 2015

v1.0.1

1.0.1.0

Yii2 behaviors implement handling of mongodb embedded documents

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sergey Sipatov
by ICC

15/07 2015

v1.0

1.0.0.0

Yii2 behaviors implement handling of mongodb embedded documents

  Sources   Download

MIT

The Requires

 

by Sergey Sipatov
by ICC