#13710: raw() sql bug when using joins ------------------------------------------+--------------------------------- Reporter: Renskers | Owner: nobody Status: new | Milestone: Component: Database layer (models, ORM) | Version: 1.2 Keywords: raw sql joins | Stage: Unreviewed Has_patch: 0 | ------------------------------------------+--------------------------------- 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 }}} -- Ticket URL: <http://code.djangoproject.com/ticket/13710> Django <http://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-upda...@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.