- Patch #1325628 by damien_vancouver, xjm, Damien Tournoud, TravisCarden: fixed EntityFieldQuery::propertyQuery missing fully qualified column names causes ambiguous column DB error.
parent
1d4a4a2126
commit
364fd1776e
|
@ -809,7 +809,7 @@ class EntityFieldQuery {
|
|||
$select_query->addExpression(':entity_type', 'entity_type', array(':entity_type' => $entity_type));
|
||||
// Process the property conditions.
|
||||
foreach ($this->propertyConditions as $property_condition) {
|
||||
$this->addCondition($select_query, "$base_table." . $property_condition['column'], $property_condition);
|
||||
$this->addCondition($select_query, $base_table . '.' . $property_condition['column'], $property_condition);
|
||||
}
|
||||
// Process the four possible entity condition.
|
||||
// The id field is always present in entity keys.
|
||||
|
@ -817,7 +817,7 @@ class EntityFieldQuery {
|
|||
$id_map['entity_id'] = $sql_field;
|
||||
$select_query->addField($base_table, $sql_field, 'entity_id');
|
||||
if (isset($this->entityConditions['entity_id'])) {
|
||||
$this->addCondition($select_query, $sql_field, $this->entityConditions['entity_id']);
|
||||
$this->addCondition($select_query, $base_table . '.' . $sql_field, $this->entityConditions['entity_id']);
|
||||
}
|
||||
|
||||
// If there is a revision key defined, use it.
|
||||
|
@ -825,7 +825,7 @@ class EntityFieldQuery {
|
|||
$sql_field = $entity_info['entity keys']['revision'];
|
||||
$select_query->addField($base_table, $sql_field, 'revision_id');
|
||||
if (isset($this->entityConditions['revision_id'])) {
|
||||
$this->addCondition($select_query, $sql_field, $this->entityConditions['revision_id']);
|
||||
$this->addCondition($select_query, $base_table . '.' . $sql_field, $this->entityConditions['revision_id']);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -850,7 +850,13 @@ class EntityFieldQuery {
|
|||
}
|
||||
$id_map['bundle'] = $sql_field;
|
||||
if (isset($this->entityConditions['bundle'])) {
|
||||
$this->addCondition($select_query, $sql_field, $this->entityConditions['bundle'], $having);
|
||||
if (!empty($entity_info['entity keys']['bundle'])) {
|
||||
$this->addCondition($select_query, $base_table . '.' . $sql_field, $this->entityConditions['bundle'], $having);
|
||||
}
|
||||
else {
|
||||
// This entity has no bundle, so invalidate the query.
|
||||
$select_query->where('1 = 0');
|
||||
}
|
||||
}
|
||||
|
||||
// Order the query.
|
||||
|
@ -863,7 +869,7 @@ class EntityFieldQuery {
|
|||
$select_query->orderBy($id_map[$key], $order['direction']);
|
||||
}
|
||||
elseif ($order['type'] == 'property') {
|
||||
$select_query->orderBy("$base_table." . $order['specifier'], $order['direction']);
|
||||
$select_query->orderBy($base_table . '.' . $order['specifier'], $order['direction']);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1583,4 +1583,23 @@ class EntityFieldQueryTest extends WebTestBase {
|
|||
$this->fail('Exception thrown: '. $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests EFQ table prefixing with multiple conditions and an altered join.
|
||||
*
|
||||
* @see field_test_query_efq_table_prefixing_test_alter()
|
||||
*/
|
||||
function testTablePrefixing() {
|
||||
$query = new EntityFieldQuery();
|
||||
$query = $query
|
||||
->entityCondition('entity_type', 'test_entity')
|
||||
->entityCondition('bundle', 'test_bundle')
|
||||
->entityCondition('entity_id', '1')
|
||||
->addTag('efq_table_prefixing_test');
|
||||
|
||||
$expected = array(array('test_entity', 1));
|
||||
|
||||
$this->assertEntityFieldQuery($query, $expected, 'An EntityFieldQuery returns the expected results when altered with an additional join on the base table.');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -264,3 +264,14 @@ function field_test_field_widget_form_alter(&$element, &$form_state, $context) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_query_TAG_alter() for tag 'efq_table_prefixing_test'.
|
||||
*
|
||||
* @see Drupal\entity\Tests\EntityFieldQueryTest::testTablePrefixing()
|
||||
*/
|
||||
function field_test_query_efq_table_prefixing_test_alter(&$query) {
|
||||
// Add an additional join onto the entity base table. This will cause an
|
||||
// exception if the EFQ does not properly prefix the base table.
|
||||
$query->join('test_entity','te2','%alias.ftid = test_entity.ftid');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue