﻿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
9394	Querying a many-to-many intermediate model from a manager on a multi-table inherited model produces extraneous queries	Erin Kelly	nobody	"With the following models:
{{{
class Place(models.Model):
    name = models.CharField(max_length=50)

class Business(Place):
    owner = models.CharField(max_length=50)

class Restaurant(Business):
    rating = models.IntegerField()

class Chef(models.Model):
    name = models.CharField(max_length=50)
    restaurants = models.ManyToManyField(Restaurant, through='Employee')

class Employee(models.Model):
    restaurant = models.ForeignKey(Restaurant)
    chef = models.ForeignKey(Chef)
    years_of_service = models.IntegerField()
}}}
we can do {{{some_restaurant.employee_set.all()}}}, which results in three queries.  The first two queries are just retrieving the attributes of the inherited Business and Place models, which is unnecessary since all that information already exists on the some_restaurant object.  Only one query should be needed."		new	Database layer (models, ORM)	dev					Unreviewed	0	0	0	0		
