Answer the question
In order to leave comments, you need to log in
Condition for intermediate table yii2?
Hello.
There is an intermediate table ( category_assign )
| источник | ссылка | тип (0 категория ссылается на категорию, 1 - страница ссылается на категорию)
id | resource_id | category_id | type
модель категории:
public function getAdditionalCategories()
{
return $this->hasMany(self::className(), ['id' => 'category_id'])
->viaTable(CategoryAssign::tableName(), ['resource_id' => 'id']);
}
Answer the question
In order to leave comments, you need to log in
Try like this:
public function getAdditionalCategories()
{
return $this->hasMany(self::className(), ['id' => 'category_id'])
->viaTable(CategoryAssign::tableName(), ['resource_id' => 'id'], function(ActiveQuery $query){
return $query->andWhere(['type' => 0]);
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question