Hi all ,
I have three Models :
-
User : id,username,email…etc
-
Category : id,name
-
UserCategory : user_id, category_id
User Model has these relations :
public function getUserCategories()
{
return $this->hasMany(UserCategory::className(), ['user_id' => 'id']);
}
public function getCategories()
{
return $this->hasMany(Category::className(), ['id' => 'category_id'])
->via('userCategories');
}
Each user has many categories ,
How can I query users of specific category ? I want to find all users in category.id = 3 ?
Thank you