Answer the question
In order to leave comments, you need to log in
How to add a condition on which to join in Yii2 in dataProvider?
There is a fully working query in sql:
SELECT u.id, u.firstname, u.lastname, bsr.requests, bsr.found_sum
FROM user u
LEFT JOIN billing_stat_request bsr ON (bsr.id = u.id AND bsr.date = '2016-06-03')
WHERE u.company_id = 1
public function getBillingStatRequest()
{
return $this->hasOne(BillingStatRequest::className(), ['id' => 'id']);
}
$model = User::find()
->select('user.id, lastname, firstname, middlename')
->where(['company_id' => $company_id])
->joinWith('billingStatRequest bsr', true, 'LEFT JOIN');
$dataProvider = new ActiveDataProvider([
'query' => $model
]);
$model = User::find()
->select('user.id, lastname, firstname, middlename')
->where(['company_id' => '1'])
->join('LEFT JOIN', 'billing_stat_request bsr', "bsr.id = user.id AND bsr.date = 2016-06-03" );
$dataProvider = new ActiveDataProvider([
'query' => $model
]);
Answer the question
In order to leave comments, you need to log in
public function getBillingStatRequest()
{
return $this->hasOne(BillingStatRequest::className(), ['id' => 'id'])->andOnCondition(['bsr.date' => '2016-06-03']);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question