Opened 8 years ago

Closed 8 years ago

#10623 closed (invalid)

scheme for filtering an object based on a ManyToManyField or a reverse ForeignKeyField

Reported by: Andrei Khitrov Owned by: nobody
Component: Documentation Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

http://docs.djangoproject.com/en/dev/topics/db/queries/#spanning-multi-valued-relationships

filtering an object based on a ManyToManyField or a reverse ForeignKeyField:

filter_1 (condition_11, ..., condition_1n). ... .filter_k (condition_11, ..., condition_1m) == 
(condition_11 ''AND'' ... ''AND'' condition_1n) '''OR''' ... '''OR''' (condition_11 ''AND'' ... ''AND'' condition_1m)

filtering an object based NOT on a ManyToManyField or a reverse ForeignKeyField:

filter_1 (condition_11, ..., condition_1n). ... .filter_k (condition_11, ..., condition_1m) == 
(condition_11 ''AND'' ... ''AND'' condition_1n) '''AND''' ... '''AND''' (condition_11 ''AND'' ... ''AND'' condition_1m)

Change History (4)

comment:1 Changed 8 years ago by Russell Keith-Magee

Resolution: invalid
Status: newclosed

I have no idea what this ticket is referring to. Is it a correction for existing documentation? Is it a suggestion for new documentation? What problem is it trying to correct? If you're going to go to the effort of opening a ticket, PLEASE go to the effort of actually explaining the problem you are trying to fix.

comment:2 Changed 8 years ago by Andrei Khitrov

I wanted that in documentation section "filtering an object based on a ManyToManyField or a reverse ForeignKeyField" one would add some text with idea that, in general, conditions within a filter are composed through AND-operation, the same is true for composition of filters. But when conditions deal with an object based on a ManyToManyField or a reverse ForeignKeyField composition of filters goes through OR, not through AND-operation.

comment:3 Changed 8 years ago by Andrei Khitrov

Resolution: invalid
Status: closedreopened

comment:4 Changed 8 years ago by Malcolm Tredinnick

Resolution: invalid
Status: reopenedclosed

The suggested change isn't correct. All successive filter() calls are combined with "AND", no matter what fields care involved. You can see this from looking at the generated SQL.

Perhaps you are being confused by the fact that successive filters against multi-valued tables use separate copies of the table each time? The very section you refer to in the documentation explains exactly that. The filters are all combined simultaneously to the object being filtered (that is, they are "AND"-ed together) and only objects that meet all filter() criteria are in the final result set.

Note: See TracTickets for help on using tickets.
Back to Top