问题
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