10/11
2015
Wallogit.com
2017 © Pedro Peláez
Yii2 behavior
The preferred way to install this extension is through composer., (*1)
Either run, (*2)
composer require folkpro/yii2-many-has-many-behaviors
or add, (*3)
"folkpro/yii2-many-has-many-behaviors" : "*"
to the require section of your application's composer.json file., (*4)
public function behaviors()
{
return [
[
'class' => \folkpro\manyhasmanybehaviors\ManyHasManyBehavior::className(),
'relations' => [
'tags' => 'tag_items',
],
],
];
}
public function getTags()
{
return $this->hasMany(Tag::className(), ['id' => 'tag_id'])
->viaTable('post_has_tag', ['post_id' => 'id']);
}
public function rules()
{
return [
[['tag_list'], 'safe']
];
}
More information here:
ManyHasManyBehavior, (*5)