#26379: Document that first filter() chained to a RelatedManager is sticky
-------------------------------------+-------------------------------------
     Reporter:  Balázs Oroszi        |                    Owner:  Annabelle
                                     |  Wiegart
         Type:  Bug                  |                   Status:  assigned
    Component:  Documentation        |                  Version:  1.9
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Annabelle Wiegart):

 While trying to replicate the sticky vs. permissive filter behaviour with
 the docs example, I discovered another quite surprising twist. In this
 example without an explicit through model, I was not able to reproduce the
 permissive filter behaviour:


 {{{
 >>> from django.db.models import Q
 >>> arg1 = Q(headline__contains="Lennon")
 >>> arg2 = Q(headline__contains="Best")


 >>> q12 = taylor.texts.filter(arg1&arg2)
 >>> q12
 <QuerySet []>

 >>> q13 = taylor.texts.filter(arg1).filter(arg2)
 >>> q13
 <QuerySet []>
 >>> print(q13.query)
 SELECT "filterexample_entry"."id", "filterexample_entry"."blog_id",
 "filterexample_entry"."headline", "filterexample_entry"."body_text",
 "filterexample_entry"."pub_date", "filterexample_entry"."mod_date",
 "filterexample_entry"."number_of_comments",
 "filterexample_entry"."number_of_pingbacks",
 "filterexample_entry"."rating" FROM "filterexample_entry" INNER JOIN
 "filterexample_entry_authors" ON ("filterexample_entry"."id" =
 "filterexample_entry_authors"."entry_id") WHERE
 ("filterexample_entry_authors"."author_id" = 2 AND
 "filterexample_entry"."headline"::text LIKE %Lennon% AND
 "filterexample_entry"."headline"::text LIKE %Best%)
 }}}


 I would have expected q13 to produce a double JOIN and result in a
 permissive filter, but it didn't.

 Does an explicit through model make a difference in the end?
-- 
Ticket URL: <https://code.djangoproject.com/ticket/26379#comment:17>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019a59ca0c7b-7b5a6cb1-35b0-4a23-8f92-c5c1aea7dcf1-000000%40eu-central-1.amazonses.com.

Reply via email to