diff options
Diffstat (limited to 'django/db/models/sql')
| -rw-r--r-- | django/db/models/sql/query.py | 16 | ||||
| -rw-r--r-- | django/db/models/sql/subqueries.py | 5 | ||||
| -rw-r--r-- | django/db/models/sql/where.py | 2 |
3 files changed, 15 insertions, 8 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index a6957bab7b..3044882a86 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -851,7 +851,7 @@ class Query(object): return alias def fill_related_selections(self, opts=None, root_alias=None, cur_depth=1, - used=None, requested=None, restricted=None): + used=None, requested=None, restricted=None, nullable=None): """ Fill in the information needed for a select_related query. The current depth is measured as the number of connections away from the root model @@ -883,6 +883,10 @@ class Query(object): (not restricted and f.null) or f.rel.parent_link): continue table = f.rel.to._meta.db_table + if nullable or f.null: + promote = True + else: + promote = False if model: int_opts = opts alias = root_alias @@ -891,12 +895,12 @@ class Query(object): int_opts = int_model._meta alias = self.join((alias, int_opts.db_table, lhs_col, int_opts.pk.column), exclusions=used, - promote=f.null) + promote=promote) else: alias = root_alias alias = self.join((alias, table, f.column, f.rel.get_related_field().column), exclusions=used, - promote=f.null) + promote=promote) used.add(alias) self.related_select_cols.extend([(alias, f2.column) for f2 in f.rel.to._meta.fields]) @@ -905,8 +909,12 @@ class Query(object): next = requested.get(f.name, {}) else: next = False + if f.null is not None: + new_nullable = f.null + else: + new_nullable = None self.fill_related_selections(f.rel.to._meta, alias, cur_depth + 1, - used, next, restricted) + used, next, restricted, new_nullable) def add_filter(self, filter_expr, connector=AND, negate=False, trim=False, can_reuse=None): diff --git a/django/db/models/sql/subqueries.py b/django/db/models/sql/subqueries.py index 7385cd00e1..28436abede 100644 --- a/django/db/models/sql/subqueries.py +++ b/django/db/models/sql/subqueries.py @@ -2,10 +2,9 @@ Query subclasses which provide extra functionality beyond simple data retrieval. """ -from django.contrib.contenttypes import generic from django.core.exceptions import FieldError from django.db.models.sql.constants import * -from django.db.models.sql.datastructures import RawValue, Date +from django.db.models.sql.datastructures import Date from django.db.models.sql.query import Query from django.db.models.sql.where import AND @@ -43,6 +42,7 @@ class DeleteQuery(Query): More than one physical query may be executed if there are a lot of values in pk_list. """ + from django.contrib.contenttypes import generic cls = self.model for related in cls._meta.get_all_related_many_to_many_objects(): if not isinstance(related.field, generic.GenericRelation): @@ -382,4 +382,3 @@ class CountQuery(Query): def get_ordering(self): return () - diff --git a/django/db/models/sql/where.py b/django/db/models/sql/where.py index 3e8bfed087..14e54487a3 100644 --- a/django/db/models/sql/where.py +++ b/django/db/models/sql/where.py @@ -18,7 +18,7 @@ class WhereNode(tree.Node): Used to represent the SQL where-clause. The class is tied to the Query class that created it (in order to create - the corret SQL). + the correct SQL). The children in this tree are usually either Q-like objects or lists of [table_alias, field_name, field_class, lookup_type, value]. However, a |
