balderdashy / waterline-docs

WARNING: The content in this repo is out of date! See https://github.com/balderdashy/sails-docs for the most up-to-date documentation
452 stars 161 forks source link

Define an array of objects #110

Open guillaumev opened 8 years ago

guillaumev commented 8 years ago

Hi,

I'd like to define something along these lines:

module.exports = {
   attributes: {
     phone_numbers: [{
       type: {
         type: 'string',
         enum: ['Landline', 'Mobile']
       },
       number: {
          type: 'string'
       }
     }]
   }
}

but this code doesn't work in Sails.

Is it possible to define an array of objects ? From what I've read, I only have 2 options:

  1. Create a Phone model and do a one to many association between the User model and the Phone model: I'm not really interested in this solution however, as I'm not planning to search by phone number, and wouldn't want to have a specific table in my db just to store phone numbers...
  2. Define the phone_numbers attribute as type: 'array' and validate its structure by writing some code in a beforeUpdate hook

Am I right and do I have only these 2 options above available or is there a way to define an array type with a proper structure ?

Thank you.

dv336699 commented 8 years ago

this repo is for issues regard waterline documentation, I think you should get an answer if you post your question (which is not an issue) on stackoverflow