#36617: RelatedManager QuerySet with filters on the same relation do not add 
inner
joins
-------------------------------------+-------------------------------------
     Reporter:  Florian Dahms        |                     Type:  Bug
       Status:  new                  |                Component:  Database
                                     |  layer (models, ORM)
      Version:  5.2                  |                 Severity:  Normal
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
 When using the QuerySet from a RelatedManager I cannot do subsequent
 filters over the same relation.

 Given I have these models:

 {{{
 class A(models.Model):
     x = models.IntegerField()
     pass


 class B(models.Model):
     foo = models.ManyToManyField(A, related_name='bars')
 }}}

 then I would expect the following tests to pass:


 {{{
 class ExampleTestCase(TestCase):
     def setUp(self):
         A.objects.create(x=1)
         A.objects.create(x=2)
         b = B.objects.create()
         b.foo.set(A.objects.all())

     def test_1(self):
 self.assertEqual(B.objects.filter(foo__x=1).filter(foo__x=2).count(),
                          1)

     def test_2(self):
         self.assertEqual(A.objects.get(x=1).bars.filter(foo__x=2).count(),
                          1)
 }}}

 The QuerySet from {{{B.objects.filter(foo__x=1)}}} behaves different than
 the one from {{{A.objects.get(x=1).bars}}} (I would expect them to behave
 in the same way). In test_1, the SQL has two INNER JOINs and in test_2 it
 is only one.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36617>
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/0107019975b71d0b-8aa1ce68-b14a-4fdf-a162-caa81434f122-000000%40eu-central-1.amazonses.com.

Reply via email to