Selecting all columns with Inner Join in Active Record

廉价感情. 提交于 2020-01-16 03:42:07

问题


In the Ruby on Rails Guide I see examples using Joins. For example

Category.joins(:posts)

results in the query

SELECT categories.* FROM categories
  INNER JOIN posts ON posts.category_id = categories.id

This is all well and good, but how can I get returned both the categories AND posts columns using Active Record? Or am I totally missing something with SQL?


回答1:


You need to call #includes:

Category.includes(:posts)


来源:https://stackoverflow.com/questions/14947820/selecting-all-columns-with-inner-join-in-active-record

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!