-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update ActiveDataProvider::prepareModels() to avoid SQL error with UNION queries #20246
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -101,17 +101,29 @@ | |||||
throw new InvalidConfigException('The "query" property must be an instance of a class that implements the QueryInterface e.g. yii\db\Query or its subclasses.'); | ||||||
} | ||||||
$query = clone $this->query; | ||||||
|
||||||
$has_union = $query->union && count($query->union); | ||||||
if (($pagination = $this->getPagination()) !== false) { | ||||||
$pagination->totalCount = $this->getTotalCount(); | ||||||
if ($pagination->totalCount === 0) { | ||||||
return []; | ||||||
} | ||||||
$query->limit($pagination->getLimit())->offset($pagination->getOffset()); | ||||||
if ($has_union) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
$query->union[count($query->union)-1]['query']->limit($pagination->getLimit())->offset($pagination->getOffset()); | ||||||
Check failure on line 112 in framework/data/ActiveDataProvider.php GitHub Actions / PHP_CodeSniffer
Check failure on line 112 in framework/data/ActiveDataProvider.php GitHub Actions / PHP_CodeSniffer
|
||||||
} else { | ||||||
$query->limit($pagination->getLimit())->offset($pagination->getOffset()); | ||||||
} | ||||||
} | ||||||
if (($sort = $this->getSort()) !== false) { | ||||||
$query->addOrderBy($sort->getOrders()); | ||||||
} | ||||||
if ($has_union) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if ($query->orderBy) { | ||||||
$query->union[count($query->union)-1]['query']->addOrderBy($query->orderBy); | ||||||
Check failure on line 122 in framework/data/ActiveDataProvider.php GitHub Actions / PHP_CodeSniffer
|
||||||
$query->orderBy = null; | ||||||
} | ||||||
} | ||||||
|
||||||
return $query->all($this->db); | ||||||
} | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.