Issue #3015691 by hchonov, mondrake: entityQueryAggregate queries cannot be executed more than once
parent
e58e520bba
commit
576bc7fea7
|
@ -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 @@ class Query extends QueryBase implements QueryInterface {
|
|||
$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 @@ class EntityQueryAggregateTest extends EntityKernelTestBase {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue