How to embed and write mongo objects in Sails.js (more than one level)?

From the sails.js example,

//Person.js

var Person = { attributes: { firstName: 'STRING', lastName: 'STRING', age: { type: 'INTEGER', max: 150, required: true } birthDate: 'DATE', phoneNumber: { type: 'STRING', defaultsTo: '111-222-3333' } emailAddress: { type: 'email', // Email type will get validated by the ORM required: true } } }; 

Now, how can I add emailAddress to have home and office as inline fields?

Tried to do it like this:

 emailAddress: { { work: { type: 'email', }, personal: { type: 'email', } } }, 

and

 emailAddress: { attributes: { work: { type: 'email', }, personal: { type: 'email', } } }, 

both do not work. I get errors like "There are no rules for attributes" for the second case, "Unexpected token {" in the first case.

+7
javascript express
source share
2 answers

Ok, after a few threads on this. Sails Waterline does not seem to support the MongoDB inline schema at this point. You can write your own contribution or force it, but you also need to hack support out of the box (model verification), etc. https://github.com/balderdashy/sails-mongo/issues/44

Another option - sails-mongoose, unfortunately, is also not supported. Where can we determine the name of the collection when using the mongoose sail? package in node.js + sailsjs?

Update . Starting with V0.10, Sails supports associations. Perhaps this will make it work. Still experimental.

Update . Using the functionality of associations, you can force the use of the scheme in different models and create links between them, but so far it does not seem that you can implement them - link them only from different collections / tables.

+10
source share

https://github.com/balderdashy/sails-mongo/issues/44

It seems that they are already planned as a Feature Feature.

+1
source share

All Articles