﻿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
13710	raw() sql bug when using a model with many fields with long names	Kevin Renskers	Tobias McNulty	"I love the new raw() function to write custom sql and get back ORM objects. However, when using joins, things get weird. 

As long as you use ""select *"", everything works fine: 
{{{
for r in Model.objects.raw('SELECT * FROM model INNER JOIN othermodel ON othermodel.model_id = model.id'): 
    print r 
}}}

However, this can result in a LOT of columns that you don't need, and possible duplicate column names. 

Solution would seem to be this: 
{{{
for r in Model.objects.raw('SELECT model.id, model.name FROM model INNER JOIN othermodel ON othermodel.model_id = model.id'): 
    print r 
}}}

Sadly, this doesn't work. I get an ""type() argument 1 must be string, not unicode"" error from django/db/models/query_utils.py in deferred_class_factory, line 274.

Weirdly enough, this does work: 
{{{
for r in Model.objects.raw('SELECT model.* FROM model INNER JOIN othermodel ON othermodel.model_id = model.id'): 
    print r 
}}}"	Uncategorized	closed	Database layer (models, ORM)	1.2	Normal	invalid	raw sql joins deffered class		Unreviewed	0	0	0	0	0	0
