这是我的用户模型:我试图在用户之间创建一个自反的关联。导师和学员
fullName: {
type: 'string',
required: true,
description: 'Full representation of the user\'s name',
maxLength: 120,
example: 'Lisa Microwave van der Jenny'
},
typeOfUser: {
required: true,
type: 'string',
example: 'mentor',
description: 'The user\'s type of account.',
},
skills:{
collection:'skills',
via: 'userId'
},
mentees:{
collection: 'user',
via: 'mentors'
},
mentors:{
collection:'user',
via: 'mentees'
}
这是我的密码。
// Add mentor of mentorId as the mentor of currentUser
await User.addToCollection(3, 'mentor',8);
// Find mentor and populate mentees
var showMentee = await User.findOne(8).populate('mentee');
回答正确:
{
"mentee": [
{
"id": 3,
"fullName": "1234",
"typeOfUser": "mentee"
}
],
"id": 8,
"fullName": "1234",
"typeOfUser": "mentor"
}
但问题在于sails创建的关联表:
+----+-------------+-------------+
| id | user_mentee | user_mentor |
+----+-------------+-------------+
| 1 | 8 | 3 |
| 2 | 8 | 3 |
+----+-------------+-------------+
我不能理解这种情况下的列命名。导师id是8,学员id是3,但显示的是相反的。
暂无答案!
目前还没有任何答案,快来回答吧!