﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
36617	RelatedManager QuerySet with filters on the same relation do not add inner joins	Florian Dahms		"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."	Bug	closed	Documentation	5.2	Normal	duplicate			Unreviewed	0	0	0	0	0	0
