Commit 8a128c64 authored by Dries's avatar Dries

- Patch #851748 by Stevel: weird logic in SelectQuery::addField().

parent b8a7b8a8
......@@ -1125,14 +1125,14 @@ public function addField($table_alias, $field, $alias = NULL) {
}
// If that's already in use, try the table name and field name.
if (!empty($this->tables[$alias])) {
if (!empty($this->fields[$alias])) {
$alias = $table_alias . '_' . $field;
}
// If that is already used, just add a counter until we find an unused alias.
$alias_candidate = $alias;
$count = 2;
while (!empty($this->tables[$alias_candidate])) {
while (!empty($this->fields[$alias_candidate])) {
$alias_candidate = $alias . '_' . $count++;
}
$alias = $alias_candidate;
......
......@@ -1543,6 +1543,16 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
sort($sorted_ids_second_set);
$this->assertEqual($sorted_ids_second_set, $sorted_ids, t('After sorting the second random list, the result matches the sorted version of the first random list.'));
}
/**
* Test that aliases are renamed when duplicates.
*/
function testSelectDuplicateAlias() {
$query = db_select('test', 't');
$alias1 = $query->addField('t', 'name', 'the_alias');
$alias2 = $query->addField('t', 'age', 'the_alias');
$this->assertNotIdentical($alias1, $alias2, 'Duplicate aliases are renamed.');
}
}
/**
......
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