D
D
Daniil Sidorov2018-09-24 13:12:56
Yii
Daniil Sidorov, 2018-09-24 13:12:56

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:

  • id
  • check_id
  • repair_id
  • is_main

I want to get a repair on this request (with the condition is_main = 0). I am making a request.
$re_repair = Repair::find()
            ->leftJoin('CheckList', 'CheckList.check_id = ' . $check->id)
            ->where(['CheckList.is_main' => 0])
            ->all();

Why am I getting the error
Watch error

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
)


Please help me figure out what the error is.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2018-09-24
@webinar

table name Repair was not inserted
check table names to match

D
Daniil Sidorov, 2018-09-24
@DaniLaFokc

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 question

Ask a Question

731 491 924 answers to any question