mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 13:02:24 +08:00
Fix #20175: Fix bad result for pagination when used with GridView
This commit is contained in:
@ -110,7 +110,6 @@ class ActiveDataProvider extends BaseDataProvider
|
||||
if (($sort = $this->getSort()) !== false) {
|
||||
$query->addOrderBy($sort->getOrders());
|
||||
}
|
||||
|
||||
return $query->all($this->db);
|
||||
}
|
||||
|
||||
@ -128,7 +127,6 @@ class ActiveDataProvider extends BaseDataProvider
|
||||
$keys[] = call_user_func($this->key, $model);
|
||||
}
|
||||
}
|
||||
|
||||
return $keys;
|
||||
} elseif ($this->query instanceof ActiveQueryInterface) {
|
||||
/* @var $class \yii\db\ActiveRecordInterface */
|
||||
@ -148,13 +146,13 @@ class ActiveDataProvider extends BaseDataProvider
|
||||
$keys[] = $kk;
|
||||
}
|
||||
}
|
||||
|
||||
return $keys;
|
||||
}
|
||||
|
||||
return array_keys($models);
|
||||
}
|
||||
|
||||
private $_totalCount = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -163,8 +161,13 @@ class ActiveDataProvider extends BaseDataProvider
|
||||
if (!$this->query instanceof QueryInterface) {
|
||||
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;
|
||||
return (int) $query->limit(-1)->offset(-1)->orderBy([])->count('*', $this->db);
|
||||
$query = (clone $this->query)->limit(-1)->offset(-1)->orderBy([]);
|
||||
$key = md5((string)$query);
|
||||
|
||||
if (!array_key_exists($key, $this->_totalCount)) {
|
||||
$this->_totalCount[$key] = (int)$query->count('*', $this->db);
|
||||
}
|
||||
return $this->_totalCount[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -196,7 +199,6 @@ class ActiveDataProvider extends BaseDataProvider
|
||||
if (is_object($this->query)) {
|
||||
$this->query = clone $this->query;
|
||||
}
|
||||
|
||||
parent::__clone();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user