On Oct 2, 5:42 pm, "Sean O'Connor" <sean.b.ocon...@gmail.com> wrote: > To be honest this seems like something which would be a lot of work with > relatively little gain. For this to work raw() would need to change from a > relatively simple bit of code which doesn't need to touch all of the complex > query code in the ORM to a complex bit of code which needs to deeply modify > the behavior of the query code.
Perhaps I exposed my thinking process too much. Surely .raw() should remain as-is and raw_extra() *added*, being orthogonal to raw() both usage- and implementation-wise. And it should certainly be labeled as "only use this if you know what you're doing." As for the usefulness, I believe I'm not the only one who builds queries dynamically a lot (e.g. according to GET/POST parameters: if 'foo' in request.GET: q = q.filter(...)) before evaluating it. For that use case, raw() does not help -- I'd have to glue together SQL strings to build the query manually, like the ORM does, which is obviously fragile (think about tracking joins) and defies the purpose of an ORM. Mixing .filter() with .raw_extra() would be a cleaner way to execute advanced SQL. As for the implementation, I took a superficial glance at django/db/models/sql/query.py before posting and e.g. the ORDER BY override looked quite doable in as_sql(). Let me provide an oversimplified, naive example: --- django/db/models/sql/query.py (revision 11594) +++ django/db/models/sql/query.py (working copy) @@ -446,7 +446,9 @@ result.append('HAVING %s' % having) params.extend(h_params) - if ordering: + if self.raw_order_by: + result.append(self.raw_order_by) + elif ordering: result.append('ORDER BY %s' % ', '.join(ordering)) But let me stop right here. If it doesn't look sensible to RKM or you, let it be, lengthy arguments in similar situations have been futile (and e.g. in case of http://code.djangoproject.com/ticket/10697#comment:4 and the corresponding django-dev thread, brought me bad karma which I obviously don't have any use of :) ). --- Finally let me express my thanks that you've taken the trouble of implementing raw(). The prospect of having it in Django is excellent news. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---