L
L
Lander2016-05-05 17:11:29
MySQL
Lander, 2016-05-05 17:11:29

How to compose such a query in Yii2 via AR?

Good afternoon.
We need a tricky selection of two tables. There were no problems with the Join of the first table, but the second one needs a double condition:


...LEFT JOIN `reject` `r` ON ( `r`.`u_id` = `q`.`id` AND `r`.`processing_id` = `p`.`id` )...

The corresponding relay is described:
public function getReject()
{
  return $this->hasMany(Reject::className(), ['u_id' => 'id']);
}

Question: How to file such a tricky condition for a join?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Donkovtsev, 2016-05-06
@Demetriy

public function getReject()
{
  return $this->hasMany(Reject::className(), ['u_id' => 'id'])->onCondition('reject.processing_id = p.id');
}

Something like this probably, only instead of p.id the name of the correct table or alias.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question