scott scott - 8 days ago 7
Node.js Question

Sails.js Same Model many to many association

Sails.js .10 rc8

I've completely run out of ideas for this

I have a model called User and I want to associate it in a collection to other users like a friends list. Like a many-to-many association

//User.js
friends: {
collection: 'user',
via: 'friends'
}


but when I run
.populate('friends')

it doesn't populate anything. Any ideas?

Answer

Your models should look like this...

//User.js
friends: {
  collection: 'friend',
  via: 'user'
}

//Friend.js
user: {
  model: 'user'
  via: 'friends'
}

Also sails 10 rc8 is old. You should be on sails 10.5