Answer the question
In order to leave comments, you need to log in
Why is query not working in yii2?
Hello. I have 2 models: Application ( Check ) and Repair ( Repair ). They are interconnected using an intermediate table CheckList
The CheckList table contains the following fields:
$re_repair = Repair::find()
->leftJoin('CheckList', 'CheckList.check_id = ' . $check->id)
->where(['CheckList.is_main' => 0])
->all();
Error Info: Array
(
[0] => 42000
[1] => 1064
[2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'check WHERE `CheckList`.`is_main`=0' at line 1
)
Answer the question
In order to leave comments, you need to log in
In the end, it turned out that I wrote some kind of nonsense.
Did it like this:
$re_repair = Repair::find()
->leftJoin('CheckList', 'CheckList.repair_id = Repair.id')
->leftJoin('Check', 'Check.id = CheckList.check_id')
->where(['CheckList.is_main' => 0])
->andWhere(['Check.id' => $check->id])
->one();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question