Unverified Commit 78da9a1d authored by alexpott's avatar alexpott

Issue #2986887 by hchonov, tstoeckler, amateescu, alexpott: Impossible entity...

Issue #2986887 by hchonov, tstoeckler, amateescu, alexpott: Impossible entity query with condition on revision metadata keys
parent ea33b157
......@@ -184,6 +184,7 @@ public function addField($field, $type, $langcode) {
// finds the property first. The data table is preferred, which is why
// it gets added before the base table.
$entity_tables = [];
$revision_table = NULL;
if ($all_revisions && $field_storage && $field_storage->isRevisionable()) {
$data_table = $entity_type->getRevisionDataTable();
$entity_base_table = $entity_type->getRevisionTable();
......@@ -191,11 +192,18 @@ public function addField($field, $type, $langcode) {
else {
$data_table = $entity_type->getDataTable();
$entity_base_table = $entity_type->getBaseTable();
if ($field_storage && $field_storage->isRevisionable() && in_array($field_storage->getName(), $entity_type->getRevisionMetadataKeys())) {
$revision_table = $entity_type->getRevisionTable();
}
}
if ($data_table) {
$this->sqlQuery->addMetaData('simple_query', FALSE);
$entity_tables[$data_table] = $this->getTableMapping($data_table, $entity_type_id);
}
if ($revision_table) {
$entity_tables[$revision_table] = $this->getTableMapping($revision_table, $entity_type_id);
}
$entity_tables[$entity_base_table] = $this->getTableMapping($entity_base_table, $entity_type_id);
$sql_column = $specifier;
......
......@@ -1163,4 +1163,42 @@ public function testWithTwoEntityReferenceFieldsToSameEntityType() {
$this->assertEquals($entity->id(), reset($result));
}
/**
* Tests entity queries with condition on the revision metadata keys.
*/
public function testConditionOnRevisionMetadataKeys() {
$this->installModule('entity_test_revlog');
$this->installEntitySchema('entity_test_revlog');
/** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
$entity_type_manager = $this->container->get('entity_type.manager');
/** @var \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type */
$entity_type = $entity_type_manager->getDefinition('entity_test_revlog');
/** @var \Drupal\Core\Entity\ContentEntityStorageInterface $storage */
$storage = $entity_type_manager->getStorage('entity_test_revlog');
$revision_created_timestamp = time();
$revision_created_field_name = $entity_type->getRevisionMetadataKey('revision_created');
$entity = $storage->create([
'type' => 'entity_test',
$revision_created_field_name => $revision_created_timestamp,
]);
$entity->save();
// Query only the default revision.
$result = $storage->getQuery()
->condition($revision_created_field_name, $revision_created_timestamp)
->execute();
$this->assertCount(1, $result);
$this->assertEquals($entity->id(), reset($result));
// Query all revisions.
$result = $storage->getQuery()
->condition($revision_created_field_name, $revision_created_timestamp)
->allRevisions()
->execute();
$this->assertCount(1, $result);
$this->assertEquals($entity->id(), reset($result));
}
}
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