Browse Source

Updated README

tags/1.4.0
Alban Jubert 7 years ago
parent
commit
1be081e86b
  1. 29
      README.md

29
README.md

@ -50,7 +50,18 @@ class Project extends \yii\db\ActiveRecord
...
'saveRelations' => [
'class' => SaveRelationsBehavior::className(),
'relations' => ['users', 'company']
'relations' => [
'company',
'users',
'tags' => [
'extraColumns' => function ($model) {
/** @var $model Tag */
return [
'order' => $model->order
];
}
]
],
],
];
}
@ -89,6 +100,13 @@ class Project extends \yii\db\ActiveRecord
return $this->hasMany(User::className(), ['id' => 'user_id'])->via('ProjectUsers');
}
/**
* @return ActiveQuery
*/
public function getTags()
{
return $this->hasMany(Tag::className(), ['id' => 'tag_id'])->viaTable('ProjectTags', ['project_id' => 'id']);
}
}
```
> Though not mandatory, it is highly recommended to activate the transactions for the owner model.
@ -129,6 +147,15 @@ Attributes of the related model will be massively assigned using the `load() met
> See the PHPUnit tests for more examples.
Populate additional junction table columns in a many-to-many relation
---------------------------------------------------------------------
In a many-to-many relation involving a junction table additional column values can be saved to the junction table for each model.
> **Note:**
> If junction table properties are configured for a relation the rows associated with the related models in the junction table will be deleted and inserted again on each saving
> to ensure that changes to the junction table properties are saved too.
> See the configuration section for examples.
Validation
----------
Every declared related models will be validated prior to be saved. If any validation fails, for each related model attribute in error, an error associated with the named relation will be added to the owner model.

Loading…
Cancel
Save