Last active
August 29, 2015 14:08
-
-
Save shunchu/112903dce62572342549 to your computer and use it in GitHub Desktop.
add associated object's IDs as arrays for each record in collection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add associated object's IDs as arrays for each record in collection | |
Organization.joins(:users) | |
.select("organizations.*, '#{User.joins(:organization).pluck(:id)}' as user_ids") | |
.group('organizations.id') | |
# => { organizations: [{ id: 1, name: 'some name',... user_ids:[1,2,3] }] } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment