How do I make a recursive relationship in sails?

Diagram: enter image description here

I want to have an array with all friend user ids, for example:

{
   id: 1
   name: 'Javi',
   email: '123@gmail.com',
   friends: [2]
}

{
    id: 2,
    name: 'User2',
    email: '321@gmail.com',
    friends: [1]
}

      

I tried with this:

// User.js <-- model
attributes:{
   name: 'string',
   email:{type:'email', required: true}
   friends:{
     collection: 'User',
     via: 'friends'
   },
}

      

I cannot achieve this.

+3


source to share


1 answer


Add primaryKey: true

to your ID so the sails will understand your link.



0


source







All Articles