Ticket #7907: 7907.patch
File 7907.patch, 1.7 KB (added by , 16 years ago) |
---|
-
django/db/models/sql/query.py
541 541 result.append('%s%s%s' % (connector, qn(name), alias_str)) 542 542 first = False 543 543 for t in self.extra_tables: 544 if isinstance(t, tuple): 545 t, subselect = t 546 else: 547 subselect = None 544 548 alias, unused = self.table_alias(t) 545 549 # Only add the alias if it's not already present (the table_alias() 546 550 # calls increments the refcount, so an alias refcount of one means 547 551 # this is the only reference. 548 552 if alias not in self.alias_map or self.alias_refcount[alias] == 1: 549 553 connector = not first and ', ' or '' 550 result.append('%s%s' % (connector, qn(alias))) 554 if subselect is None: 555 result.append('%s%s' % (connector, qn(alias))) 556 else: 557 result.append('%s%s as %s' % (connector, subselect, qn(alias))) 551 558 first = False 552 559 return result, [] 553 560 … … 1560 1567 if params: 1561 1568 self.extra_params += tuple(params) 1562 1569 if tables: 1563 self.extra_tables += tuple(tables) 1570 # allow tables to be dictionaries mapping names to subselects 1571 if hasattr(tables, 'items'): 1572 self.extra_tables += tuple(tables.items()) 1573 else: 1574 self.extra_tables += tuple(tables) 1564 1575 if order_by: 1565 1576 self.extra_order_by = order_by 1566 1577