﻿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
1547	Wrong column name in SQL ORDER BY statement	Nebojsa Djordjevic <nesh at studioquattro dot co dot yu>	Adrian Holovaty	"When I have models like this:
{{{
#!python
class Foo(models.Model):
   a = models.SlugField('a')
   class Admin:
     pass

class Bar(models.Model):
   a = models.SlugField('a')
   class Admin:
     pass

class Baz(models.Model):
   parent = models.OneToOneField(Foo)
   bar = models.ForeignKey(Bar)
   class Admin:
     pass
}}}

Any attempt to access Baz model thru admin interface fails with {{{OperationalError at <address> no such column: <app>_foo.id}}} and generated SQL looks like this:

{{{
SELECT ""<app>_baz"".""parent_id"",""<app>_baz"".""bar_id"" FROM ""<app>_baz"" ORDER BY ""<app>_foo"".""id"" ASC
}}}

I think that correct SQL is more like this:
{{{
SELECT ""<app>_baz"".""parent_id"",""<app>_baz"".""bar_id"" FROM ""<app>_baz"" ORDER BY ""<app>_baz"".""foo_id"" ASC
}}}

Current workaround is that I must declare model like this:
{{{
#!python
class Baz(models.Model):
   parent = models.OneToOneField(Foo)
   bar = models.ForeignKey(Bar)
   class Meta:
       ordering = ['?']
   class Admin:
     pass
}}}

Note '''[?]''' for forcing '''no ordering'''.

If I have time I'll lookup into source to find what's going on (and hopefully submit a patch), or I'm simply doing something wrong here?"	defect	closed	Database layer (models, ORM)	magic-removal	normal	duplicate		nesh@…	Unreviewed	0	0	0	0	0	0
