Arrays 如何在sails模型中声明数组?
我一直面临一个问题,需要类似阵列的模型。我目前的模式是Arrays 如何在sails模型中声明数组?,arrays,sails.js,sails-mongo,Arrays,Sails.js,Sails Mongo,我一直面临一个问题,需要类似阵列的模型。我目前的模式是 module.exports = { attributes: { foodname:{ type: 'string', unique: true, required: true, }, foodreview:'string', foodlocation:'string', foodcategory:'string', foodupvote:'intege
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:{}
}
};
实现这一目标的最佳方式是什么 我们可以像这样使用'array'类型:
module.exports = {
attributes: {
name: { type: 'string' },
title: { type: 'string'},
keywords: { type: 'array' },
}
};