﻿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
15807	order by 'pk' alias doesn't work with inherited models when parent has an ordering set	Mathieu Pillard	nobody	"Consider the following models:

{{{
#!python
from django.db import models

class Foo(models.Model):
    bar = models.PositiveSmallIntegerField(default=1)
    class Meta:
        ordering = ['bar']
        
class Child(Foo):
    barchild = models.PositiveSmallIntegerField(default=1)
}}}

Trying to get the Child objects, ordering by 'id', works:
{{{
>>> str(Child.objects.order_by('id').query)
'SELECT ""test_pk_foo"".""id"", ""test_pk_foo"".""bar"", ""test_pk_child"".""foo_ptr_id"", ""test_pk_child"".""barchild"" FROM ""test_pk_child"" INNER JOIN #""test_pk_foo"" ON (""test_pk_child"".""foo_ptr_id"" = ""test_pk_foo"".""id"") ORDER BY ""test_pk_child"".""foo_ptr_id"" ASC'
}}}

However, trying to order by 'pk' doesn't (see the `ORDER BY` clause):
{{{
>>> str(Child.objects.order_by('pk').query)
'SELECT ""test_pk_foo"".""id"", ""test_pk_foo"".""bar"", ""test_pk_child"".""foo_ptr_id"", ""test_pk_child"".""barchild"" FROM ""test_pk_child"" INNER JOIN #""test_pk_foo"" ON (""test_pk_child"".""foo_ptr_id"" = ""test_pk_foo"".""id"") ORDER BY ""test_pk_foo"".""bar"" ASC'
}}}

The default ordering from the parent is used instead! Removing the `ordering` property or using `id` instead of `pk` works, but I expected `pk` to work.

I reproduced this with django 1.2, 1.3 and trunk, with sqlite and postgresql_psycopg2 backends."	Bug	closed	Database layer (models, ORM)	dev	Normal	wontfix			Unreviewed	0	0	0	0	0	0
