Ticket #2922 - Defining outer joins

4 views
Skip to first unread message

Jonathan Buchanan

unread,
Feb 1, 2007, 8:54:21 AM2/1/07
to django-d...@googlegroups.com
http://code.djangoproject.com/ticket/2922

Could I ask that the functionality proposed in this ticket be
reconsidered for inclusion?

I've encountered a situation where I need to be able to add an outer
join and *also* use the ON clause to specify conditions additional to
the primary key join generated when Q objects are used instead, as was
suggested in the thread [1] linked to with the ticket closing message.

I intended to use QuerySet's 'extra' method to add a 'direction'
property to all retrieved objects which indicated whether the current
user had voted the object up, down, or hadn't voted on the object at
all (to be used when displaying something like Reddit's voting
widgets, but in this case applicable to any model thanks to generic
views). Sample SQL is as follows:

SELECT aa.*, v.direction
FROM anyapp_anymodel aa
LEFT OUTER JOIN votes_vote v
ON v.object_id = aa.id
AND v.user_id = 2
AND v.content_type_id = 15
WHERE aa.id = 1;

Putting the extra conditions in the WHERE clause instead results in a
row not being retrieved at all if the user hasn't voted on the object
it represents.

Thanks,
Jonathan.

[1] http://groups.google.com/group/django-developers/browse_thread/thread/e071bb8bf57ec0a7

Reply all
Reply to author
Forward
0 new messages