1

I have been facing a issue which needs the array like model. my current model is

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

Now i want to add vote array in this, so that i can know how much upvote and downvote a food got. user should vote only once for a food. So what i need is something like this

   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:{}
      }
    };

What is the best way to achieve this?

divakar
  • 1,379
  • 6
  • 15
  • 31

1 Answers1

0

We can use the 'array' type like this:

module.exports = {
    attributes: {
    name: { type: 'string' },
        title: { type: 'string'},
        keywords: { type: 'array' },
    }
};
bmustata
  • 597
  • 9
  • 19