﻿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
930	[patch] Leaving out ¨ordering¨ in OneToOne relationship causes bad SQL statement	EABinGA	Russell Keith-Magee	"Using Trunk rev-1461:

Given the Model Foo: 


{{{
from django.core import meta

# Create your models here.

class Bar(meta.Model):
    class META:
        admin = meta.Admin()
        
    bardata = meta.CharField(maxlength=200)
    
    def __repr__(self):
        return self.bardata
        
class Baz(meta.Model):
    class META:
        admin = meta.Admin()
        
    bazdata = meta.CharField(maxlength=200)
    bar = meta.OneToOneField(Bar)

    def __repr__(self):
        return self.bazdata
}}}

When you select ¨baz¨ from the main admin interface:

You are greeted by the following:

{{{
OperationalError at /admin/foo/bazs/
no such column: foo_bars.id
Request Method: 	GET
Request URL: 	http://127.0.0.1:8080/admin/foo/bazs/
Exception Type: 	OperationalError
Exception Value: 	no such column: foo_bars.id
Exception Location: 	/usr/lib/python2.4/site-packages/Django-0.90-py2.4.egg/django/core/db/backends/sqlite3.py in execute, line 71
}}}

The offending SQL statement seems to be:

{{{
SELECT ""foo_bazs"".""bazdata"",""foo_bazs"".""bar_id"" FROM ""foo_bazs"" ORDER BY ""foo_bars"".""id"" DESC
}}}

Explicitly including an ¨ordering¨ in the ¨baz¨ class fixes this problem, but it should work properly without one.

ALSO:
Upon creation of a ¨baz¨, the admin interface of ¨baz¨ shows a label of ¨ID¨ folowed by a dropdown list containing bars followed by what seems to be the PK of said bar. What is the purpose of that number? Is it supposed to be there.

Additionally, once a baz is saved, the dropdown list suggests, that corresponding bar for this baz can be changed, but saving the baz with a different bar does not seem to have any effect.

"	defect	closed	Metasystem		normal	duplicate			Unreviewed	1	0	0	0	0	0
