Changed Query.get_columns() to quote the 'AS' column names in an extra_select situation, to match pre-queryset-refactor behavior. Added unit tests that verify this and provide an example
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7502 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
13a6fd61c6
commit
14d6ee2dc9
|
@ -394,7 +394,8 @@ class Query(object):
|
|||
some cases to avoid ambiguitity with nested queries.
|
||||
"""
|
||||
qn = self.quote_name_unless_alias
|
||||
result = ['(%s) AS %s' % (col, alias) for alias, col in self.extra_select.iteritems()]
|
||||
qn2 = self.connection.ops.quote_name
|
||||
result = ['(%s) AS %s' % (col, qn2(alias)) for alias, col in self.extra_select.iteritems()]
|
||||
aliases = set(self.extra_select.keys())
|
||||
if with_aliases:
|
||||
col_aliases = aliases.copy()
|
||||
|
|
|
@ -398,4 +398,16 @@ u'\u6797\u539f \u3081\u3050\u307f'
|
|||
>>> s = set([a10, a11, a12])
|
||||
>>> Article.objects.get(headline='Article 11') in s
|
||||
True
|
||||
|
||||
# The 'select' argument to extra() supports names with dashes in them, as long
|
||||
# as you use values().
|
||||
>>> Article.objects.filter(pub_date__year=2008).extra(select={'dashed-value': '1'}).values('headline', 'dashed-value')
|
||||
[{'headline': u'Article 11', 'dashed-value': 1}, {'headline': u'Article 12', 'dashed-value': 1}]
|
||||
|
||||
# If you use 'select' with extra() and names containing dashes on a query
|
||||
# that's *not* a values() query, those extra 'select' values will silently be
|
||||
# ignored.
|
||||
>>> articles = Article.objects.filter(pub_date__year=2008).extra(select={'dashed-value': '1', 'undashedvalue': '2'})
|
||||
>>> articles[0].undashedvalue
|
||||
2
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue