2014-10-10 15 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,以這種方式帆明白你的參考。