Skip to content

Commit a76bd53

Browse files
committed
multiple pk where logic updated in dataprovider
1 parent c754561 commit a76bd53

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

commands/NewController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,10 @@ public function actionPdo()
153153

154154
print_r($result);
155155
}
156+
157+
public function actionTest()
158+
{
159+
$q = Address::find()->andWhere(['IN', ['id', 'city_id'], [['id' => 1, 'city_id' => 1], ['id' => 3, 'city_id' => 2]]])->createCommand()->getRawSql();
160+
$a = 1;
161+
}
156162
}

qrm/ActiveRecord/QueryRelationDataProvider.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,17 @@ protected function prepareModels()
8181
->offset($offset)
8282
->all();
8383

84-
$models = $this->queryRelationManager->filter(function(Query $q) use ($pkValues, $mainTable) {
85-
$orWheres = ['OR'];
86-
foreach($pkValues as $rows) {
87-
$orWhere = [];
88-
foreach($rows as $field => $value) {
89-
$orWhere["`{$mainTable->alias}`.`$field`"] = $value;
90-
}
91-
$orWheres[] = $orWhere;
84+
$pkValuesPrefixed = [];
85+
foreach($pkValues as $row) {
86+
$rowPrefixed = [];
87+
foreach($row as $field => $value) {
88+
$rowPrefixed["`{$mainTable->alias}`.`{$field}`"] = $value;
9289
}
90+
$pkValuesPrefixed[] = $rowPrefixed;
91+
}
9392

94-
$q->andWhere($orWheres);
93+
$models = $this->queryRelationManager->filter(function(Query $q) use ($pkFields, $pkValuesPrefixed, $mainTable) {
94+
$q->andWhere(['in', $pkFields, $pkValuesPrefixed]);
9595
})->all();
9696
}
9797
}

0 commit comments

Comments
 (0)