Set additional conditions for JOIN

8 views
Skip to first unread message

Boris Shemigon

unread,
May 28, 2012, 3:59:39 PM5/28/12
to django...@googlegroups.com
Hi,

I wonder is there a way to generate a query with joins with more than one condition? For example:

SELECT o.id FROM object
JOIN object_value AS ov1 ON ov1.o_id=object.id AND ov1.field_id=1 AND ov1.value=2
JOIN object_value AS ov2 ON ov2.o_id=object.id AND ov2.field_id=2 AND ov2.value>=1
JOIN object_value AS ov3 ON ov3.o_id=object.id AND ov3.field_id=3 AND ov3.value>=2

It's supposed to find all objects that have all fields with corresponding values. 

Does anybody know how to code that in the frame of Django ORM. Or the only solution is to go down to SQL?

akaariai

unread,
May 28, 2012, 4:18:51 PM5/28/12
to Django users
There is currently no way to add conditions to the join clause, not
even by using internal APIs.

- Anssi
Reply all
Reply to author
Forward
0 new messages