rails - rails4中使用left,right outer join

访问量: 48

参考:  https://stackoverflow.com/questions/24358805/left-outer-join-in-rails-4/24358839

注意: 可以在joins方法中增加SQL语句,就可以了. 记得: 要指定外键的关联. 例如: on a.fk_id = b.id

left outer join: 
User.joins('left outer join workers on workers.user_id = users.id')

right outer join: 
User.joins('right outer join workers on workers.user_id = users.id')

订阅/RSS Feed

Subscribe

分类/category