Opened 16 years ago

Closed 16 years ago

#10623 closed (invalid)

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

Reported by: while0pass 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: no UI/UX: no

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 by Russell Keith-Magee, 16 years ago

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 by while0pass, 16 years ago

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 by while0pass, 16 years ago

Resolution: invalid
Status: closedreopened

comment:4 by Malcolm Tredinnick, 16 years ago

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