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 15161,ManyToManyField with a through model with to_field set returns no results,adehnert,Carl Meyer,"If you create a model that has a ManyToManyField with through=IntermediateModel, and you set to_field on one of the ForeignKeys in the IntermediateModel, the ManyToManyField won't properly produce the right set of results. For example, using the attached set of models, I get: {{{ >>> import manytomany.models >>> foobar = manytomany.models.FooBar.objects.all()[0] >>> foobar >>> manytomany.models.FooBar.objects.filter(foo=foobar.foo) [] >>> foobar.foo.bars.all() [] >>> foobar2 = manytomany.models.FooBar2.objects.all()[0] >>> foobar2 >>> manytomany.models.FooBar2.objects.filter(foo=foobar2.foo) [] >>> foobar2.foo.bars.all() [] }}} I would expect filter(foo=foo) to produce basically the same set of results as foo.bars (except with the FooBar objects instead of the Bar objects). However, while the former produces results, the latter does not. I suspect this is related to the behavior experienced in http://www.mail-archive.com/django-users@googlegroups.com/msg105967.html. However, while that seems like arguably not a bug, this behavior does seem to clearly qualify (or, at least, should be better-documented than I was finding it to be).",,closed,"Database layer (models, ORM)",1.2,,fixed,,,Accepted,0,0,0,0,0,0