1
0
mirror of https://github.com/django/django.git synced 2025-07-06 10:49:17 +00:00

queryset-refactor: Reverted [6762] because it generates invalid SQL. It only worked accidentally with SQLite.

Refs #4002.


git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6961 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-12-19 13:06:45 +00:00
parent 4dc766c9e1
commit 7292cc8d60
3 changed files with 3 additions and 23 deletions

View File

@ -723,16 +723,8 @@ class Query(object):
opts = self.model._meta opts = self.model._meta
alias = self.join((None, opts.db_table, None, None)) alias = self.join((None, opts.db_table, None, None))
try: field, target, unused, join_list, = self.setup_joins(parts, opts,
field, target, unused, join_list = self.setup_joins(parts, opts, alias, (connector == AND))
alias, (connector == AND))
except TypeError, e:
if len(parts) != 1 or parts[0] not in self.extra_select:
raise e
# Filtering on some alias from extra(select=...)
self.where.add([None, parts[0], None, lookup_type, value],
connector)
return
col = target.column col = target.column
alias = join_list[-1][-1] alias = join_list[-1][-1]

View File

@ -5,7 +5,6 @@ import datetime
from django.utils import tree from django.utils import tree
from django.db import connection from django.db import connection
from django.db.models.fields import Field
from datastructures import EmptyResultSet from datastructures import EmptyResultSet
# Connection types # Connection types
@ -103,10 +102,7 @@ class WhereNode(tree.Node):
else: else:
format = '%s %s' format = '%s %s'
if field: params = field.get_db_prep_lookup(lookup_type, value)
params = field.get_db_prep_lookup(lookup_type, value)
else:
params = Field().get_db_prep_lookup(lookup_type, value)
if lookup_type in connection.operators: if lookup_type in connection.operators:
return (format % (field_sql, return (format % (field_sql,

View File

@ -458,19 +458,11 @@ thus fail.)
>>> Item.objects.extra(select=SortedDict(s), params=params).values('a','b')[0] >>> Item.objects.extra(select=SortedDict(s), params=params).values('a','b')[0]
{'a': u'one', 'b': u'two'} {'a': u'one', 'b': u'two'}
Bug #4002
Attributes used in extra(select=...) are available for use in subsequent
order_by() and filter() calls.
# Order by the number of tags attached to an item. # Order by the number of tags attached to an item.
>>> l = Item.objects.extra(select={'count': 'select count(*) from queries_item_tags where queries_item_tags.item_id = queries_item.id'}).order_by('-count') >>> l = Item.objects.extra(select={'count': 'select count(*) from queries_item_tags where queries_item_tags.item_id = queries_item.id'}).order_by('-count')
>>> [o.count for o in l] >>> [o.count for o in l]
[2, 2, 1, 0] [2, 2, 1, 0]
# Filter those items that have exactly one tag attached.
>>> Item.objects.extra(select={'count': 'select count(*) from queries_item_tags where queries_item_tags.item_id = queries_item.id'}).filter(count=1)
[<Item: four>]
Bug #6154 Bug #6154
Multiple filter statements are joined using "AND" all the time. Multiple filter statements are joined using "AND" all the time.