Re: [Django] #9394: Querying a many-to-many intermediate model from a manager on a multi-table inherited model produces extraneous queries

2008-10-24 Thread Django
#9394: Querying a many-to-many intermediate model from a manager on a 
multi-table
inherited model produces extraneous queries
---+
  Reporter:  ikelly| Owner:  mtredinnick
Status:  assigned  | Milestone: 
 Component:  Database layer (models, ORM)  |   Version:  SVN
Resolution:|  Keywords: 
 Stage:  Accepted  | Has_patch:  0  
Needs_docs:  0 |   Needs_tests:  0  
Needs_better_patch:  0 |  
---+
Changes (by mtredinnick):

  * owner:  nobody => mtredinnick
  * status:  new => assigned
  * stage:  Unreviewed => Accepted

Comment:

 Turns out this doesn't have anything in particular to do with many-to-many
 and "through". It's actually a general wart in the way reverse relations
 work with model inheritance. From a bit of poking around, it might be a
 little fiddly to get it working efficiently, too. However, I've got a test
 case now that demonstrates the problem, so I'll poke at it some more.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #9394: Querying a many-to-many intermediate model from a manager on a multi-table inherited model produces extraneous queries

2008-10-18 Thread Django
#9394: Querying a many-to-many intermediate model from a manager on a 
multi-table
inherited model produces extraneous queries
---+
  Reporter:  ikelly| Owner:  nobody
Status:  new   | Milestone:
 Component:  Database layer (models, ORM)  |   Version:  SVN   
Resolution:|  Keywords:
 Stage:  Unreviewed| Has_patch:  0 
Needs_docs:  0 |   Needs_tests:  0 
Needs_better_patch:  0 |  
---+
Old description:

> 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(ChineseRestaurant,
> through='Employee')
>
> class Employee(models.Model):
> restaurant = models.ForeignKey(ChineseRestaurant)
> 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 description:

 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.

Comment (by ramiro):

 (edited code example in the description as per Ian's note above, replacing
 `ChineseRestaurant` with `Restaurant`.)

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



Re: [Django] #9394: Querying a many-to-many intermediate model from a manager on a multi-table inherited model produces extraneous queries

2008-10-17 Thread Django
#9394: Querying a many-to-many intermediate model from a manager on a 
multi-table
inherited model produces extraneous queries
---+
  Reporter:  ikelly| Owner:  nobody
Status:  new   | Milestone:
 Component:  Database layer (models, ORM)  |   Version:  SVN   
Resolution:|  Keywords:
 Stage:  Unreviewed| Has_patch:  0 
Needs_docs:  0 |   Needs_tests:  0 
Needs_better_patch:  0 |  
---+
Changes (by ikelly):

  * needs_better_patch:  => 0
  * needs_tests:  => 0
  * needs_docs:  => 0

Comment:

 The occurrences of !ChineseRestaurant in the models should just be
 Restaurant.  Sorry about that.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---



[Django] #9394: Querying a many-to-many intermediate model from a manager on a multi-table inherited model produces extraneous queries

2008-10-17 Thread Django
#9394: Querying a many-to-many intermediate model from a manager on a 
multi-table
inherited model produces extraneous queries
--+-
 Reporter:  ikelly|   Owner:  nobody
   Status:  new   |   Milestone:
Component:  Database layer (models, ORM)  | Version:  SVN   
 Keywords:|   Stage:  Unreviewed
Has_patch:  0 |  
--+-
 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(ChineseRestaurant,
 through='Employee')

 class Employee(models.Model):
 restaurant = models.ForeignKey(ChineseRestaurant)
 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.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~--~~~~--~~--~--~---