Answer the question
In order to leave comments, you need to log in
How to search by multiple tags in Yii2 ActiveQuery?
There are three tables t1, t2, t3. There is also a join table t123, which stores links between three tables.
We need to pull all records from t3 that match one specific record in t1 and one or more records from t2.
In t123, records are stored as:
id t1 t2 t3
1 1 1 1
2 1 2 2
3 1 2 3
4 1 3 1
t123::find()->joinWith('t3')
->select('t3.id')
->where([
't123.t1' => $t1,
])->andWhere('in','t2',$t2arr)->column();
Answer the question
In order to leave comments, you need to log in
I could be wrong, but probably the problem is that joinWith does a LEFT JOIN by default, and you need InnerJoinWith()
www.yiiframework.com/doc-2.0/yii-db-activequery.ht...
PS. In general, it seems to me that your database structure is not quite right. Will you reveal the names of the tables?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question