Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 如何在sails模型中声明数组?_Arrays_Sails.js_Sails Mongo - Fatal编程技术网

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' },
    }
};