Issue #1828790 by plach, chx, pfrenssen: Fixed Entity count query not working with fields shared among different entity types.
parent
6bfcc56a31
commit
238ffe4f74
|
@ -69,6 +69,7 @@ class Query extends QueryBase {
|
|||
$entity_tables[$base_table] = drupal_get_schema($base_table);
|
||||
$sqlQuery = $this->connection->select($base_table, 'base_table', array('conjunction' => $this->conjunction));
|
||||
$sqlQuery->addMetaData('configurable_fields', $configurable_fields);
|
||||
$sqlQuery->addMetaData('entity_type', $entity_type);
|
||||
// Determines the key of the column to join on. This is either the entity
|
||||
// id key or the revision id key, depending on whether the entity type
|
||||
// supports revisions.
|
||||
|
|
|
@ -129,7 +129,8 @@ class Tables {
|
|||
if ($field['cardinality'] != 1) {
|
||||
$this->sqlQuery->addMetaData('simple_query', FALSE);
|
||||
}
|
||||
$this->fieldTables[$field_name] = $this->addJoin($type, $table, "%alias.$field_id_field = base_table.$entity_id_field", $langcode);
|
||||
$entity_type = $this->sqlQuery->getMetaData('entity_type');
|
||||
$this->fieldTables[$field_name] = $this->addJoin($type, $table, "%alias.$field_id_field = base_table.$entity_id_field AND %alias.entity_type = '$entity_type'", $langcode);
|
||||
}
|
||||
return $this->fieldTables[$field_name];
|
||||
}
|
||||
|
|
|
@ -367,6 +367,37 @@ class EntityQueryTest extends WebTestBase {
|
|||
$this->assertResult(range(15, 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test entity count query.
|
||||
*/
|
||||
protected function testCount() {
|
||||
// Attach the existing 'figures' field to a second entity type so that we
|
||||
// can test whether cross entity type fields produce the correct query.
|
||||
$field_name = $this->figures;
|
||||
$bundle = $this->randomName();
|
||||
$instance = array(
|
||||
'field_name' => $field_name,
|
||||
'entity_type' => 'test_entity_bundle',
|
||||
'bundle' => $bundle,
|
||||
);
|
||||
field_create_instance($instance);
|
||||
|
||||
$entity = entity_create('test_entity_bundle', array(
|
||||
'ftid' => 1,
|
||||
'fttype' => $bundle,
|
||||
));
|
||||
$entity->enforceIsNew();
|
||||
$entity->setNewRevision();
|
||||
$entity->save();
|
||||
// As the single entity of this type we just saved does not have a value
|
||||
// in the color field, the result should be 0.
|
||||
$count = $this->factory->get('test_entity_bundle')
|
||||
->exists("$field_name.color")
|
||||
->count()
|
||||
->execute();
|
||||
$this->assertFalse($count);
|
||||
}
|
||||
|
||||
protected function assertResult() {
|
||||
$assert = array();
|
||||
$expected = func_get_args();
|
||||
|
|
Loading…
Reference in New Issue