Reputation: 529
Uing Ruby (1.8.7) and Mongo Driver, I've written this:
@data['Users'] = []
@database['user_facilities'].find({ :facility_id => @facility['id'] }).each do |user_facility|
@data['Users'] << @database['users'].find({ :id => user_facility['user_id'] }).to_a
end
Which outputs:
[ "Users", [ [ { "name" => "michael" }, { "name" => "dennis" } ], [ { "name" => "brandon" }, { "name" => "steve" } ] ] ]
But I'd like it to look like this:
[ "Users", [ { "name" => "michael" }, { "name" => "dennis" }, { "name" => "brandon" }, { "name" => "steve" } ] ]
I understand why I get the results I do above. I've tried "flatten" and "merge." But nothing seems to return data as I want it.
Upvotes: 0
Views: 97
Reputation: 83680
@database['user_facilities'].find({ :facility_id => @facility['id'] }).each do |user_facility|
@data['Users'].push *@database['users'].find({ :id => user_facility['user_id'] }).to_a
end
Upvotes: 1