开发者

ActiveRecord joins syntax

I need to express the following join condition using ActiveRecord:

SELECT ...
FROM U
LEFT OUTER JOIN F ON U.key = F.foreign_key
 AND F.key = ?
WHERE ...

where ? is substituted at run time.

The following causes a SQL-syntax error:

joins("LEFT OUTER JOIN F on U.key = F.foreign_key AND F.key=?", key)

I can't seem to determine if Activ开发者_运维技巧eRecord supports this 'dynamic substitution' (whatever this is called).

Adding the restriction (where("F.key=?", key)) in the WHERE clause will collapse the OUTER JOIN to a JOIN.


This syntax worked:

joins("LEFT OUTER JOIN F on U.key = F.foreign_key AND F.key=#{key}")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜