2014-10-10 48 views
3

图: enter image description here如何在sails中做出递归关系?

我想与朋友用户的所有ID的阵列,像这样:

{ 
    id: 1 
    name: 'Javi', 
    email: '[email protected]', 
    friends: [2] 
} 

{ 
    id: 2, 
    name: 'User2', 
    email: '[email protected]', 
    friends: [1] 
} 

我试着用这样的:

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

我不能做到这一点。

回答

0

添加一个primaryKey: true在你的ID,以这种方式帆明白你的参考。