I'm struggling upon a problem related to Sails.js and Waterline associations. The database technology is mongoDB and I'm using the sails-mongo adapter. I have a model User which has an association with a Role model. The association is of one-to-many type. The association is declared as follows:
/** -------------------------
* User.js
* ---------------------------
*/
{...}
role: {
model: 'Role'
},
{...}
/** -------------------------
* Role.js
* ---------------------------
*/
{...}
users: {
collection: 'Role',
via: 'role'
},
{...}
When I make a query to retrieve all the users and I populate the role attribute, I have the role attribute populated with the first role inserted in the database even for those users that don't have any role associated.
Anyone had encountered this problem? Thanks a lot.