Answer the question
In order to leave comments, you need to log in
How to do Join with multiple conditions in yii2?
Everything is precious time.
Help me figure out
there is a table tbl1 (id, name), a second table tbl2 (id, id_tbl, name_tbl, name)
how to make a query correctly if the second table has no connection with the first, that is, the second table has an id of the first that can be repeated, and more the name of the first table, but the id can be the same since there can be a 3rd table.
Please show with an example. I already looked through Google, I didn’t see
in the picture, I hope it’s clear what I want
Answer the question
In order to leave comments, you need to log in
У вас же есть name_tbl, по нему и ориентируйтесь.
А вообще лучше 2 таблицы как tbl2 и не париться, а общее выбирать через union.
Вы не описали какой конкретно запрос Вы не можете составить. Поэтому вот пример наугад:
В модели к таблице 1:
public function getMydata(){
return $this->hasMany(SecondModel::classname(),['id_tbl'=>'id'])->andWhere(['name_tbl'=>'tbl1'])
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question