-2

How can I write this query in Ruby on Rails to select includes model attributes like: Post.includes(:comment).select(:name, :title, :comments => [:email, :text])

1 Answers1

0

ActiveRecord#select doesn't support hashes as arguments, but you could use syntax like this:

Post.joins(:comment).select(:name, :title).merge(Comment.select(:email, :text))

But keep in mind that if Post has 3 comments it will return 3 instances of Post each with different comment data.

P. Boro
  • 716
  • 3
  • 12