Commit f4315766 authored by webchick's avatar webchick

#316868 by Crell: Make addField() alias to the field name, rather than the...

#316868 by Crell: Make addField() alias to the field name, rather than the table and field name when there are no conflicts.
parent 1fa03d7c
......@@ -335,10 +335,17 @@ public function distinct($distinct = TRUE) {
* The unique alias that was assigned for this field.
*/
public function addField($table_alias, $field, $alias = NULL) {
// If no alias is specified, first try the field name itself.
if (empty($alias)) {
$alias = $field;
}
// If that's already in use, try the table name and field name.
if (!empty($this->tables[$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])) {
......
......@@ -1014,7 +1014,7 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
$result = $query->execute();
// Check that the aliases are being created the way we want.
$this->assertEqual($name_field, 'test_name', t('Name field alias is correct.'));
$this->assertEqual($name_field, 'name', t('Name field alias is correct.'));
$this->assertEqual($age_field, 'age', t('Age field alias is correct.'));
// Ensure that we got the right record.
......@@ -1034,7 +1034,7 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
$result = $query->execute();
// Check that the aliases are being created the way we want.
$this->assertEqual($name_field, 'test_name', t('Name field alias is correct.'));
$this->assertEqual($name_field, 'name', t('Name field alias is correct.'));
$this->assertEqual($age_field, 'double_age', t('Age field alias is correct.'));
// Ensure that we got the right record.
......
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