我有一个用户模型和地址模型。当我做 @user=User.all 它返回
{ "id" : "1",
"firstname" : "test",
"username" : "test",
},
{ "id" : "2",
"firstname" : "test1",
"username" : "test2",
}
当我这样做的时候@address =Address.all
{ "id" : "21",
"user_id" : "1",
"city" : "test",
"country" : "test",
},
{ "id" : "22",
"user_id" : "2",
"city" : "test1",
"country" : "test2",
}
我得到高于价值
现在我想将@user 和@ddress 这两个值合并到一个哈希中。像前-
{ "id" : "1",
"firstname" : "test",
"username" : "test",
"id" : "22",
"user_id" : "1",
"city" : "test1",
"country" : "test2",
},
{ "id" : "2",
"firstname" : "test2",
"username" : "test2",
"id" : "22",
"user_id" : "2",
"city" : "test1",
"country" : "test2",
}
这个怎么做?