Issue #3189174 by tstoeckler, daffie: Entity query fails for multi-property base fields if no property is specified

merge-requests/177/head
catch 2020-12-21 17:44:01 +00:00
parent d1064c3fe3
commit 4a3f45abfc
2 changed files with 29 additions and 4 deletions

View File

@ -250,6 +250,14 @@ class Tables implements TablesInterface {
$key++;
}
}
// If there are no additional specifiers but the field has a main
// property, use that to look up the column name.
elseif ($field_storage && $column) {
$columns = $field_storage->getColumns();
if (isset($columns[$column])) {
$sql_column = $table_mapping->getFieldColumnName($field_storage, $column);
}
}
$table = $this->ensureEntityTable($index_prefix, $sql_column, $type, $langcode, $base_table, $entity_id_field, $entity_tables);
}

View File

@ -975,7 +975,7 @@ class EntityQueryTest extends EntityKernelTestBase {
'name' => $this->randomMachineName(),
'vid' => 'tags',
'description' => [
'value' => $this->randomString(),
'value' => 'description1',
'format' => 'format1',
],
]);
@ -985,20 +985,37 @@ class EntityQueryTest extends EntityKernelTestBase {
'name' => $this->randomMachineName(),
'vid' => 'tags',
'description' => [
'value' => $this->randomString(),
'value' => 'description2',
'format' => 'format2',
],
]);
$term2->save();
// Test that the properties can be queried directly.
$ids = $this->container->get('entity_type.manager')
->getStorage('taxonomy_term')
->getQuery()
->condition('description.value', 'description1')
->execute();
$this->assertCount(1, $ids);
$this->assertEquals($term1->id(), reset($ids));
$ids = $this->container->get('entity_type.manager')
->getStorage('taxonomy_term')
->getQuery()
->condition('description.format', 'format1')
->execute();
$this->assertCount(1, $ids);
$this->assertEqual($term1->id(), reset($ids));
$this->assertEquals($term1->id(), reset($ids));
// Test that the main property is queried if no property is specified.
$ids = $this->container->get('entity_type.manager')
->getStorage('taxonomy_term')
->getQuery()
->condition('description', 'description1')
->execute();
$this->assertCount(1, $ids);
$this->assertEquals($term1->id(), reset($ids));
}
/**