我知道,在船帆我可以用填充连接两个模型,如在这个环节Sails model and orm 例如描述我有2个型号:如何使用连接到连接两个表中帆
// myApp/api/models/Pet.js
module.exports = {
attributes: {
name: {
type: 'string'
},
color: {
type: 'string'
}
}
}
和
// myApp/api/models/User.js
module.exports = {
attributes: {
name: {
type: 'string'
},
age: {
type: 'integer'
},
pony:{
model: 'pet'
}
}
}
然后
User.find({ name:'Mike' })
.populate('pony')
.exec(function(err, users) {}
将返回结果的东西像
[{
name: 'Mike',
age: 21,
pony: {
name: 'Pinkie Pie',
color: 'pink',
id: 5,
createdAt: Tue Feb 11 2014 15:45:33 GMT-0600 (CST),
updatedAt: Tue Feb 11 2014 15:45:33 GMT-0600 (CST)
},
createdAt: Tue Feb 11 2014 15:48:53 GMT-0600 (CST),
updatedAt: Tue Feb 11 2014 15:48:53 GMT-0600 (CST),
id: 1
}]
在这里
小马
是一个对象,我不喜欢这样。我想要返回这样的事情:
[{
name: 'Mike',
age: 21,
name: 'Pinkie Pie',
color: 'pink',
id: 5,
createdAt: Tue Feb 11 2014 15:45:33 GMT - 0600 (CST),
updatedAt: Tue Feb 11 2014 15:45:33 GMT - 0600 (CST)
createdAt: Tue Feb 11 2014 15:48:53 GMT - 0600 (CST),
updatedAt: Tue Feb 11 2014 15:48:53 GMT - 0600 (CST),
id: 1
}]
(所有这些都是属性)。所以我认为我需要加入这种情况。我怎么能加入?
您的预期结果对象具有重复键。这应该是一个JS对象或JSON? – Sangharsh
@Sangharsh我会在加入时重命名 – Tuan