Commit 61ff24ef authored by webchick's avatar webchick

Issue #1292922 by loganfsmyth, plach: Fixed EntityFieldQuery count query...

Issue #1292922 by loganfsmyth, plach: Fixed EntityFieldQuery count query broken for translatable fields.
parent c2b82b6c
......@@ -6,3 +6,4 @@ core = 8.x
required = TRUE
files[] = entity.query.inc
files[] = entity.controller.inc
files[] = tests/entity_query.test
......@@ -1048,6 +1048,46 @@ class EntityFieldQueryTestCase extends DrupalWebTestCase {
$this->assertTrue($pass, t("Can't query the universe."));
}
/**
* Tests querying translatable fields.
*/
function testEntityFieldQueryTranslatable() {
// Make a test field translatable AND cardinality one.
$this->fields[0]['translatable'] = TRUE;
$this->fields[0]['cardinality'] = 1;
field_update_field($this->fields[0]);
field_test_entity_info_translatable('test_entity', TRUE);
drupal_static_reset('field_available_languages');
// Create more items with different languages.
$entity = new stdClass();
$entity->ftid = 1;
$entity->ftvid = 1;
$entity->fttype = 'test_bundle';
// Set fields in two languages with one field value.
foreach (array(LANGUAGE_NONE, 'en') as $langcode) {
$entity->{$this->field_names[0]}[$langcode][0]['value'] = 1234;
}
field_attach_update('test_entity', $entity);
// Look up number of results when querying a single entity with multilingual
// field values.
$query = new EntityFieldQuery();
$query_count = $query
->entityCondition('entity_type', 'test_entity')
->entityCondition('bundle', 'test_bundle')
->entityCondition('entity_id', '1')
->fieldCondition($this->fields[0])
->count()
->execute();
$this->assertEqual($query_count, 1, t("Count on translatable cardinality one field is correct."));
}
/**
* Tests field meta conditions.
*/
......
......@@ -493,7 +493,7 @@ function field_sql_storage_field_storage_query(EntityFieldQuery $query) {
$select_query->fields($table_alias, array('entity_type', 'entity_id', 'revision_id', 'bundle'));
$field_base_table = $table_alias;
}
if ($field['cardinality'] != 1) {
if ($field['cardinality'] != 1 || $field['translatable']) {
$select_query->distinct();
}
}
......
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