Loopbackjs 具有环回的对偶归属关系
我有几段关系要做模特Loopbackjs 具有环回的对偶归属关系,loopbackjs,strongloop,Loopbackjs,Strongloop,我有几段关系要做模特 邮件属于两个配置文件(发件人和收件人) 注册包括一个配置文件和一个课程 我试图用2 hasOne做1,但最终得到了Profile.messageId { "name": "Message", "base": "PersistedModel", "idInjection": true, "options": { "validateUpsert": true }, "properties": { "id": { "type":
{
"name": "Message",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"id": {
"type": "number",
"id": true,
"required": true
},
"text": {
"type": "string",
"required": true
},
"created": {
"type": "date",
"required": true
},
"seen": {
"type": "boolean",
"required": true
}
},
"validations": [],
"relations": {
"sender": {
"type": "hasOne",
"model": "Profile",
"foreignKey": ""
},
"recipient": {
"type": "hasOne",
"model": "Profile",
"foreignKey": ""
}
},
"acls": [],
"methods": []
}
同样的问题w/#2
为什么使用2个hasOne关系而不是hasMany关系?我是否应该这样做2与不同的外国密钥名称(发送者、接收者)有很多关系?对于注册-它将是一个直通模型。个人资料将与课程有密切关系,反之亦然@兄弟,你应该试试。如果成功了,就把它作为答案贴出来,然后接受它。我相信问题的出现是因为您没有指定foreignkey,所以环回正在指定默认值。@FaridNouriNeshat-我将很快发布我的解决方案:)谢谢提醒。仍然在使用样本数据来确保我得到了我想要的数据。
{
"name": "Enrollment",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"id": {
"type": "number",
"id": true,
"required": true
},
"created": {
"type": "date",
"required": true
},
"currentPage": {
"type": "string",
"comments": "What page are they on in this curriculum?"
}
},
"validations": [],
"relations": {
"curriculums": {
"type": "hasOne",
"model": "Curriculum",
"foreignKey": ""
},
"profiles": {
"type": "hasOne",
"model": "Profile",
"foreignKey": ""
}
},
"acls": [],
"methods": []
}