Is it possible to set a condition in the connection section via viaTable? Currently I got this:
return $this->hasMany(User::className(), ['id' => 'id_user']) ->from(User::tableName()) ->viaTable(RoomActiveUser::tableName(), ['id_room' => 'id'], function($query) { return $query->andWhere(['id_role' => RoleHelper::getConsultantRole()->id]); });
But this is a bad decision. What for? When you do a left join, the id_role condition will make it an inner join. The id_role condition must be placed inside the ON section of the connection.
I searched the website and checked the code, but I donβt see how this can be solved.
source share