Code

Opened 5 years ago

Closed 5 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: 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)

Attachments (0)

Change History (4)

comment:1 Changed 5 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

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

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

  • Resolution invalid deleted
  • Status changed from closed to reopened

comment:4 Changed 5 years ago by mtredinnick

  • Resolution set to invalid
  • Status changed from reopened to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.