Changes between Initial Version and Version 2 of Ticket #19135


Ignore:
Timestamp:
Oct 17, 2012, 2:52:32 AM (12 years ago)
Author:
Claude Paroz
Comment:

No, the example is right. The first filter will apply both conditions on the same join, while the second one will create a separate join for each condition, hence the results might be larger.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #19135

    • Property Resolutioninvalid
    • Property Status newclosed
  • Ticket #19135 – Description

    initial v2  
    22
    33That may sound a bit confusing, so hopefully an example will clarify. To select all blogs that contain entries with both "Lennon" in the headline and that were published in 2008 (the same entry satisfying both conditions), we would write:
    4 
     4{{{
    55Blog.objects.filter(entry__headline__contains='Lennon',
    66        entry__pub_date__year=2008)
    7 
     7}}}
    88To select all blogs that contain an entry with "Lennon" in the headline as well as an entry that was published in 2008, we would write:
    9 
     9{{{
    1010Blog.objects.filter(entry__headline__contains='Lennon').filter(
    1111        entry__pub_date__year=2008)
    12 
     12}}}
    1313From my understanding, the two examples are mixed up: the first example should be for the second explanation and vice versa. First example is a union of two sets: filter(setA, setB), the second example is an intersection of two sets: filter(setA).filter(setB).
Back to Top