Skip to content
Snippets Groups Projects
Commit 576bc7fe authored by catch's avatar catch
Browse files

Issue #3015691 by hchonov, mondrake: entityQueryAggregate queries cannot be executed more than once

parent e58e520b
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -21,6 +21,13 @@ class Query extends QueryBase implements QueryInterface {
*/
protected $sqlQuery;
/**
* The Tables object for this query.
*
* @var \Drupal\Core\Entity\Query\Sql\TablesInterface
*/
protected $tables;
/**
* An array of fields keyed by the field alias.
*
......@@ -101,6 +108,9 @@ protected function prepare() {
$simple_query = FALSE;
}
$this->sqlQuery = $this->connection->select($base_table, 'base_table', ['conjunction' => $this->conjunction]);
// Reset the tables structure, as it might have been built for a previous
// execution of this query.
$this->tables = NULL;
$this->sqlQuery->addMetaData('entity_type', $this->entityTypeId);
$id_field = $this->entityType->getKey('id');
// Add the key field for fetchAllKeyed().
......
......@@ -541,6 +541,38 @@ public function testAggregation() {
}
/**
* Tests preparing a query and executing twice.
*/
public function testRepeatedExecution() {
$query = $this->entityStorage->getAggregateQuery()
->groupBy('user_id');
$this->queryResult = $query->execute();
$this->assertResults([
['user_id' => 1],
['user_id' => 2],
['user_id' => 3],
]);
$entity = $this->entityStorage->create([
'id' => 7,
'user_id' => 4,
'field_test_1' => 42,
'field_test_2' => 68,
]);
$entity->enforceIsNew();
$entity->save();
$this->queryResult = $query->execute();
$this->assertResults([
['user_id' => 1],
['user_id' => 2],
['user_id' => 3],
['user_id' => 4],
]);
}
/**
* Asserts the results as expected regardless of order between and in rows.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment