Commit 238ffe4f authored by webchick's avatar webchick

Issue #1828790 by plach, chx, pfrenssen: Fixed Entity count query not working...

Issue #1828790 by plach, chx, pfrenssen: Fixed Entity count query not working with fields shared among different entity types.
parent 6bfcc56a
......@@ -69,6 +69,7 @@ public function execute() {
$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 @@ protected function ensureFieldTable(&$field_name, $type, $langcode) {
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 @@ protected function testTableSort() {
$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();
......
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