Improved code style of Query.table_alias() usage.

This commit is contained in:
Jorge C. Leitão 2014-06-14 12:50:18 +02:00
parent 0b980ef857
commit d2cbcbcc76
2 changed files with 7 additions and 7 deletions

View File

@ -546,7 +546,7 @@ class SQLCompiler(object):
result.append('%s%s%s' % (connector, qn(name), alias_str)) result.append('%s%s%s' % (connector, qn(name), alias_str))
first = False first = False
for t in self.query.extra_tables: for t in self.query.extra_tables:
alias, unused = self.query.table_alias(t) alias, _ = self.query.table_alias(t)
# Only add the alias if it's not already present (the table_alias() # Only add the alias if it's not already present (the table_alias()
# calls increments the refcount, so an alias refcount of one means # calls increments the refcount, so an alias refcount of one means
# this is the only reference. # this is the only reference.

View File

@ -664,16 +664,16 @@ class Query(object):
If 'create' is true, a new alias is always created. Otherwise, the If 'create' is true, a new alias is always created. Otherwise, the
most recently created alias for the table (if one exists) is reused. most recently created alias for the table (if one exists) is reused.
""" """
current = self.table_map.get(table_name) alias_list = self.table_map.get(table_name)
if not create and current: if not create and alias_list:
alias = current[0] alias = alias_list[0]
self.alias_refcount[alias] += 1 self.alias_refcount[alias] += 1
return alias, False return alias, False
# Create a new alias for this table. # Create a new alias for this table.
if current: if alias_list:
alias = '%s%d' % (self.alias_prefix, len(self.alias_map) + 1) alias = '%s%d' % (self.alias_prefix, len(self.alias_map) + 1)
current.append(alias) alias_list.append(alias)
else: else:
# The first occurrence of a table uses the table name directly. # The first occurrence of a table uses the table name directly.
alias = table_name alias = table_name
@ -900,7 +900,7 @@ class Query(object):
return alias return alias
# No reuse is possible, so we need a new alias. # No reuse is possible, so we need a new alias.
alias, _ = self.table_alias(table, True) alias, _ = self.table_alias(table, create=True)
if not lhs: if not lhs:
# Not all tables need to be joined to anything. No join type # Not all tables need to be joined to anything. No join type
# means the later columns are ignored. # means the later columns are ignored.