LEFT OUTER joins in Rails 3

后端 未结 8 1969
自闭症患者
自闭症患者 2020-11-27 12:31

I have the following code:

@posts = Post.joins(:user).joins(:blog).select

which is meant to find all posts and return them and the associat

8条回答
  •  旧时难觅i
    2020-11-27 13:02

    I'm a big fan of the squeel gem:

    Post.joins{user.outer}.joins{blog}
    

    It supports both inner and outer joins, as well as the ability to specify a class/type for polymorphic belongs_to relationships.

提交回复
热议问题