﻿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
28538	order_with_respect_to not working when model accessed via a many-to-many related field	Carlos Mermingas	nobody	"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
}}}"	Bug	closed	Database layer (models, ORM)	1.11	Normal	invalid			Unreviewed	0	0	0	0	0	0
