Opened 12 years ago

Closed 12 years ago

#19135 closed Uncategorized (invalid)

Example in "Spanning Multi-valued relationships" is mixed

Reported by: anonymous Owned by: nobody
Component: Documentation Version: 1.4
Severity: Normal 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 (last modified by Claude Paroz)

The example writes:

That 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:

Blog.objects.filter(entry__headline__contains='Lennon',
        entry__pub_date__year=2008)

To 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:

Blog.objects.filter(entry__headline__contains='Lennon').filter(
        entry__pub_date__year=2008)

From 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).

Change History (2)

comment:2 by Claude Paroz, 12 years ago

Description: modified (diff)
Resolution: invalid
Status: newclosed

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.

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