在rails 3中执行此查询是否有更多的方法?
scope :unblocked_on_invite, joins(
"LEFT JOIN blockers
ON blockers.member_id = members.id
AND blockers.type = 'InviteBlocker'").where("blockers.id IS NULL")
答案 0 :(得分:3)
如果您使用:include它将执行自动INNER JOIN。就LEFT JOIN而言,你正在做你应该做的事情。我能看到的唯一方法就是把它写成这样:
scope :unblocked_on_invite, joins(
"LEFT JOIN blockers
ON blockers.member_id = members.id
AND blockers.type = 'InviteBlocker'").where(:blockers => nil)