Commit f717ef85 authored by catch's avatar catch

Issue #2766135 by hchonov, jeroen.b, amateescu, neclimdul, gordon, chipway,...

Issue #2766135 by hchonov, jeroen.b, amateescu, neclimdul, gordon, chipway, jmuzz, timmillwood, daffie: EntityQuery with condition on the revision field leads to wrong results
parent 34585896
......@@ -109,13 +109,14 @@ public function addField($field, $type, $langcode) {
$column = NULL;
}
// If there is revision support, only the current revisions are being
// queried, and the field is revisionable then use the revision id.
// Otherwise, the entity id will do.
if (($revision_key = $entity_type->getKey('revision')) && $all_revisions && $field_storage && $field_storage->isRevisionable()) {
// If there is revision support, all the revisions are being queried, and
// the field is revisionable or the revision ID field itself, then use the
// revision ID. Otherwise, the entity ID will do.
$query_revisions = $all_revisions && $field_storage && ($field_storage->isRevisionable() || $field_storage->getName() === $entity_type->getKey('revision'));
if ($query_revisions) {
// This contains the relevant SQL field to be used when joining entity
// tables.
$entity_id_field = $revision_key;
$entity_id_field = $entity_type->getKey('revision');
// This contains the relevant SQL field to be used when joining field
// tables.
$field_id_field = 'revision_id';
......@@ -193,7 +194,7 @@ public function addField($field, $type, $langcode) {
// it gets added before the base table.
$entity_tables = [];
$revision_table = NULL;
if ($all_revisions && $field_storage && $field_storage->isRevisionable()) {
if ($query_revisions) {
$data_table = $entity_type->getRevisionDataTable();
$entity_base_table = $entity_type->getRevisionTable();
}
......
......@@ -275,6 +275,14 @@ public function testEntityQuery() {
$entity->name->value .= 'x';
$entity->save();
}
// Test querying all revisions with a condition on the revision ID field.
$this->queryResults = $this->storage
->getQuery()
->condition('revision_id', $first_entity->getRevisionId())
->allRevisions()
->execute();
$this->assertCount(1, $this->queryResults);
$this->assertEquals($first_entity->getRevisionId(), key($this->queryResults));
// We changed the entity names, so the current revision should not match.
$this->queryResults = $this->storage
->getQuery()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment