summaryrefslogtreecommitdiff
path: root/includes/database
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2008-10-22 04:01:03 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2008-10-22 04:01:03 +0000
commitf4315766fe31d57cd3a709d666d363bcf933febe (patch)
treeea07501721ec218f2220ffe19f620618b792f23f /includes/database
parent1fa03d7c33f30a57eb9051e5d979f41178bbcefa (diff)
downloadbrdo-f4315766fe31d57cd3a709d666d363bcf933febe.tar.gz
brdo-f4315766fe31d57cd3a709d666d363bcf933febe.tar.bz2
#316868 by Crell: Make addField() alias to the field name, rather than the table and field name when there are no conflicts.
Diffstat (limited to 'includes/database')
-rw-r--r--includes/database/select.inc7
1 files changed, 7 insertions, 0 deletions
diff --git a/includes/database/select.inc b/includes/database/select.inc
index 3adf2bd99..2be1e08d9 100644
--- a/includes/database/select.inc
+++ b/includes/database/select.inc
@@ -335,10 +335,17 @@ class SelectQuery extends Query implements QueryConditionInterface, QueryAlterab
* 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])) {