#28538: order_with_respect_to not working when model accessed via a many-to-many
related field
-------------------------------------+-------------------------------------
               Reporter:  Carlos     |          Owner:  nobody
  Mermingas                          |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  1.11
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Please let me know if I am doing something wrong or my expectation is
 incorrect. Also, if this ends up being a confirmed problem and an "easy
 picking", I'd be happy to try to fix it.

 Consider the following models for  restaurant menus:

 {{{
 class Plate(models.Model):
     name = models.CharField(max_length=100)

 class Menu(models.Model):
     name = models.CharField(max_length=100)
     plates = models.ManyToManyField(Plate, through='MenuPlate')

 class MenuPlate(models.Model):
     menu = models.ForeignKey(Menu, on_delete=models.CASCADE)
     plate = models.ForeignKey(Plate, on_delete=models.CASCADE)

     class Meta:
         order_with_respect_to = 'menu'
 }}}

 In the Django shell, after creating a few objects, notice how the first
 query has an `order by` but the second query doesn't:

 {{{
 # from menus.models import Menu, Plate, MenuPlate

 # m = Menu.objects.all().first()

 # print(MenuPlate.objects.filter(menu=m).query)
 SELECT "menus_menuplate"."id", "menus_menuplate"."menu_id",
 "menus_menuplate"."plate_id", "menus_menuplate"."_order" FROM
 "menus_menuplate" WHERE "menus_menuplate"."menu_id" = 1 ORDER BY
 "menus_menuplate"."_order" ASC

 # print(m.plates.all().query)
 SELECT "menus_plate"."id", "menus_plate"."name" FROM "menus_plate" INNER
 JOIN "menus_menuplate" ON ("menus_plate"."id" =
 "menus_menuplate"."plate_id") WHERE "menus_menuplate"."menu_id" = 1
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28538>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/053.444556d6a162a64ef4a3151b772e4b5c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to