【发布时间】:2015-04-12 06:00:08
【问题描述】:
我一直面临一个需要类似模型的数组的问题。我现在的模型是
module.exports = {
attributes: {
foodname:{
type: 'string',
unique: true,
required: true,
},
foodreview:'string',
foodlocation:'string',
foodcategory:'string',
foodupvote:'integer',
fooddownvote:'integer',
owner: {
model: 'user'
},
Comments: {
collection: 'comments',
via: 'comment'
}
}
};
现在我想在其中添加投票数组,这样我就可以知道食物得到了多少赞成和反对。用户应该只为食物投票一次。所以我需要的是这样的
module.exports = {
attributes: {
foodname:{
type: 'string',
unique: true,
required: true,
},
foodreview:'string',
foodlocation:'string',
foodcategory:'string',
foodupvote:'integer',
fooddownvote:'integer',
owner: {
model: 'user'
},
Comments: {
collection: 'comments',
via: 'comment'
},
vote:{}
}
};
实现这一目标的最佳方法是什么?
【问题讨论】:
标签: arrays sails.js sails-mongo