﻿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
34141	Prefetch querysets access to parent query through table	Jeremy Nix	nobody	"In working on a project recently, I ran into the following use-case:
1) A parent model exists with a ManyToMany field.
2) This field goes through a ManyToMany table.
3) The ManyToMany table has an attribute that I'm interested in filtering on.

I'm my use-case (see attached sample code), I'm wanting to query out parent objects and then prefetch the child associated list (in this case locations).  Prefetching is able to pull through the child associated list.  My problem is that I need to constrain on an attribute that is defined in the through table (record_status).  I do not have the luxary of being able to update my model, so I was looking for ways I could define my prefetch so that it would return back the correct associated records, but with the additional filter.  The only way I could figure out how to make it work, was to use the extra query.  Anytime I tried to add filtering logic in the prefetch that referenced CompanyLocation, I would get an error about an invalid attribute.  If I tried adding the criteria onto the Company objects portion, it would not fail compilation, but would fail querying due to multiple records being returned.  It didn't make sense to me to include it there anyway as I was not trying to constrain the Company records, but the location records collection that was being prefetched.

Maybe there is a way of doing this that I didn't find.  If not, I think it would be a good use-case to be able to make references to the through object in the prefetch itself."	Uncategorized	closed	Uncategorized	4.1	Normal	invalid	QuerySet.extra		Unreviewed	0	0	0	0	0	0
