Skip to content

Commit

Permalink
Fix Where $this->db is null
Browse files Browse the repository at this point in the history
  • Loading branch information
lav45 committed Jun 1, 2024
1 parent a6e4e0b commit 834e151
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
15 changes: 4 additions & 11 deletions framework/data/ActiveDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,11 @@ protected function prepareTotalCount()
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([])->cache()->count('*', $this->getDb());
}
$query = (clone $this->query)->limit(-1)->offset(-1)->orderBy([]);

/**
* @return Connection
*/
protected function getDb()
{
$db = clone $this->db;
$db->queryCache = $this->getQueryCache();
return $db;
return $this->getQueryCache()->getOrSet((string)$query, function () use ($query) {
return (int) $query->count('*', $this->db);
});
}

private $_queryCache;
Expand Down
13 changes: 3 additions & 10 deletions framework/data/SqlDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,10 @@ protected function prepareTotalCount()
'from' => ['sub' => "({$this->sql})"],
'params' => $this->params,
]);
return $query->cache()->count('*', $this->getDb());
}

/**
* @return Connection
*/
protected function getDb()
{
$db = clone $this->db;
$db->queryCache = $this->getQueryCache();
return $db;
return $this->getQueryCache()->getOrSet((string)$query, function () use ($query) {
return (int) $query->count('*', $this->db);
});
}

private $_queryCache;
Expand Down

0 comments on commit 834e151

Please sign in to comment.