Re: Join of any db table with Q.add_to_query

2008-11-10 Thread Malcolm Tredinnick


On Mon, 2008-11-03 at 03:02 -0800, Dima Dogadaylo wrote:
> Before merging of queryset-refactor it was possible to join any table
> with any ON clause to any queryset with help of Q.as_sql. 

It was "possible" for small values of possible that meant "extremely
fragile and didn't work in a large number of cases". That's why more
sophisticated support was needed for custom Q-like objects.

> For example,
> please see this one:
> http://www.djangosnippets.org/snippets/257/
> 
> Since Django 1.0 ORM looks like more complicated, Q.as_sql is
> disappeared (but still mentioned in docs (http://
> docs.djangoproject.com/en/dev/ref/models/fields/).

I don't see where you're seeing this reference still. A search on that
page doesn't turn up the sequence "as_sql" at all.

>  As I see from code
> Q.as_sql was replaced with Q.add_to_query(self, query, used_aliases)
> but from current code it looks like new implementation does not allow
> to use ON clause with more than 1 statements, for example:

The new code allows you to make any changes you like to the query, so
it's fully general. That is why the Query class is passed in. You write
an object that has an add_to_query() method and then you can do whatever
you like. Mostly this will involve calling query.join() and/or
query.add_filter(). Have a look at the docstring for join() in
particular to see how to promote a join to LEFT OUTER.

Regards,
Malcolm


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Join of any db table with Q.add_to_query

2008-11-03 Thread Dima Dogadaylo

Before merging of queryset-refactor it was possible to join any table
with any ON clause to any queryset with help of Q.as_sql. For example,
please see this one:
http://www.djangosnippets.org/snippets/257/

Since Django 1.0 ORM looks like more complicated, Q.as_sql is
disappeared (but still mentioned in docs (http://
docs.djangoproject.com/en/dev/ref/models/fields/). As I see from code
Q.as_sql was replaced with Q.add_to_query(self, query, used_aliases)
but from current code it looks like new implementation does not allow
to use ON clause with more than 1 statements, for example:

FROM blog LEFT JOIN cron_stats AS stats ON
stats.content_type_id = 12 AND stats.object_id = blog.id

Is it any way to use old behavior of Q.as_sql with Django 1.0 and join
any table that I want to any queryset? In other words, is it possible
to make working QLeftOuterJoin from http://www.djangosnippets.org/snippets/257/?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---