如何使用ActiveRecord编写此Join Constraint

时间:2012-04-26 16:01:44

标签: ruby-on-rails activerecord

我应该如何用ActiveRecord写这个:

select stores.id, stores.name, store_specials.active 
from stores 
left outer join store_specials on 
     (store_specials.store_id = stores.id and store_specials.special_id = 1) 
where stores.active = true;

由于

1 个答案:

答案 0 :(得分:2)

Rails 3.x

Stores.select("stores.id, stores.name, store_specials.active").joins("LEFT OUTER JOIN tore_specials ON store_specials.store_id = stores.id AND store_specials.special_id = 1).where("store_specials.active = true")

希望这就是你需要的