From f4315766fe31d57cd3a709d666d363bcf933febe Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Wed, 22 Oct 2008 04:01:03 +0000 Subject: #316868 by Crell: Make addField() alias to the field name, rather than the table and field name when there are no conflicts. --- includes/database/select.inc | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'includes/database') 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])) { -- cgit v1.2.3