diff options
| author | Anssi Kääriäinen <akaariai@gmail.com> | 2012-08-25 16:33:07 +0300 |
|---|---|---|
| committer | Anssi Kääriäinen <akaariai@gmail.com> | 2012-12-16 17:23:26 +0200 |
| commit | 69597e5bcc89aadafd1b76abf7efab30ee0b8b1a (patch) | |
| tree | f2d7969b6cd0f122282a0daa56b4d59e198c9afb /django/db/models/sql/constants.py | |
| parent | f811649710fb51e48217e9a78991735977decfd8 (diff) | |
Fixed #10790 -- Refactored sql.Query.setup_joins()
This is a rather large refactoring. The "lookup traversal" code was
splitted out from the setup_joins. There is now names_to_path() method
which does the lookup traveling, the actual work of setup_joins() is
calling names_to_path() and then adding the joins found into the query.
As a side effect it was possible to remove the "process_extra"
functionality used by genric relations. This never worked for left
joins. Now the extra restriction is appended directly to the join
condition instead of the where clause.
To generate the extra condition we need to have the join field
available in the compiler. This has the side-effect that we need more
ugly code in Query.__getstate__ and __setstate__ as Field objects
aren't pickleable.
The join trimming code got a big change - now we trim all direct joins
and never trim reverse joins. This also fixes the problem in #10790
which was join trimming in null filter cases.
Diffstat (limited to 'django/db/models/sql/constants.py')
| -rw-r--r-- | django/db/models/sql/constants.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/django/db/models/sql/constants.py b/django/db/models/sql/constants.py index 6e1d2dd87a..1c34f70169 100644 --- a/django/db/models/sql/constants.py +++ b/django/db/models/sql/constants.py @@ -18,12 +18,19 @@ QUERY_TERMS = set([ # Larger values are slightly faster at the expense of more storage space. GET_ITERATOR_CHUNK_SIZE = 100 -# Constants to make looking up tuple values clearer. +# Namedtuples for sql.* internal use. + # Join lists (indexes into the tuples that are values in the alias_map # dictionary in the Query class). JoinInfo = namedtuple('JoinInfo', 'table_name rhs_alias join_type lhs_alias ' - 'lhs_join_col rhs_join_col nullable') + 'lhs_join_col rhs_join_col nullable join_field') + +# PathInfo is used when converting lookups (fk__somecol). The contents +# describe the join in Model terms (model Options and Fields for both +# sides of the join. The rel_field is the field we are joining along. +PathInfo = namedtuple('PathInfo', + 'from_field to_field from_opts to_opts join_field') # Pairs of column clauses to select, and (possibly None) field for the clause. SelectInfo = namedtuple('SelectInfo', 'col field') |
