Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions framework/data/ActiveDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$has_union = $query->union && count($query->union);
$hasUnion = $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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ($has_union) {
if ($hasUnion) {

$query->union[count($query->union)-1]['query']->limit($pagination->getLimit())->offset($pagination->getOffset());

Check warning on line 112 in framework/data/ActiveDataProvider.php

View check run for this annotation

Codecov / codecov/patch

framework/data/ActiveDataProvider.php#L112

Added line #L112 was not covered by tests
} else {
$query->limit($pagination->getLimit())->offset($pagination->getOffset());
}
}
if (($sort = $this->getSort()) !== false) {
$query->addOrderBy($sort->getOrders());
}
if ($has_union) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ($has_union) {
if ($hasUnion) {

if ($query->orderBy) {
$query->union[count($query->union)-1]['query']->addOrderBy($query->orderBy);
$query->orderBy = null;

Check warning on line 123 in framework/data/ActiveDataProvider.php

View check run for this annotation

Codecov / codecov/patch

framework/data/ActiveDataProvider.php#L121-L123

Added lines #L121 - L123 were not covered by tests
}
}

return $query->all($this->db);
}

Expand Down