Add more documentation for #pluck method usage (multiple tables)

53 views
Skip to first unread message

Jędrek Domański

unread,
Jul 13, 2018, 2:17:32 PM7/13/18
to Ruby on Rails: Documentation
Hi,

I noticed using the Active Record #pluck method you are not limited to selecting multiple fields from a single table but also from multiple tables. In fact, you can do more than "selecting" multiple fields from multiple tables.

User.distinct.joins(categories, :comments: :likes).pluck("users.first_name || ' ' || users.last_name, categories.name, comments.ttitle, likes.do_not_like")

I spent a lot of time pulling my hair wondering how to select multiple fields from multiple tables in the most efficient way and ended up doing a lot of research in the internet and the source code. I suggest adding this to the Rails Query Interface documentation on #pluck method http://guides.rubyonrails.org/active_record_querying.html#pluck to save other people's time.

Jędrek

Xavier Noria

unread,
Aug 18, 2018, 11:50:56 AM8/18/18
to rubyonra...@googlegroups.com
Thanks, I have created an issue for this https://github.com/rails/rails/issues/33648.
Reply all
Reply to author
Forward
0 new messages