Get all nested records for multiple activerecords

Viewed 23

Lets say there are two models: User and Post where each post belongs to a user and a user can have many posts.

If you do @user.posts you get all posts for @user. But, given @users, is there a more elegant way than Post.where(user_id: @users.map(&:id)) to get all posts for @users? Something like @users.posts?

0 Answers
Related