0
Uing紅寶石(1.8.7)和蒙戈驅動器合併哈希值,我寫這樣的:一個數組裏面的
@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
,輸出:
[ "Users", [ [ { "name" => "michael" }, { "name" => "dennis" } ], [ { "name" => "brandon" }, { "name" => "steve" } ] ] ]
但我想它喜歡看起來像這樣:
[ "Users", [ { "name" => "michael" }, { "name" => "dennis" }, { "name" => "brandon" }, { "name" => "steve" } ] ]
我明白爲什麼我會得到我以上的結果。我試過「扁平化」和「合併」。但是,似乎沒有任何數據可以按照我的需要返回。
[array [0],array [1] .flatten(1)] – fl00r 2012-02-16 18:40:51