Skip to content
This repository has been archived by the owner on Oct 15, 2018. It is now read-only.

Define an array of objects #110

Open
guillaumev opened this issue Feb 16, 2016 · 1 comment
Open

Define an array of objects #110

guillaumev opened this issue Feb 16, 2016 · 1 comment

Comments

@guillaumev
Copy link

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
Copy link

dv336699 commented Mar 2, 2016

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants