患者模型
{
"name": "Patient",
"base": "PersistedModel",
"idInjection": true,
"properties": {
"createdDate": {
"type": "date"
}
},
"validations": [],
"relations": {
"profile": {
"type": "hasOne",
"model": "Profile",
"foreignKey": "profileID"
}
},
"acls": [],
"methods": []
}
病历表
id (INT)
createdDate (DATETIME)
modifiedDate (DATETIME)
剖面模型
{
"name": "Profile",
"base": "Model",
"idInjection": true,
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
}
},
"validations": [],
"relations": {
"patient": {
"type": "belongsTo",
"model": "Patient",
"foreignKey": "profileID"
}
},
"acls": [],
"methods": []
}
配置文件表
id (INT)
firstName (VARCHAR)
lastName (VARCHAR)
Q: 当我保存模型时,我POST跟踪/api/患者/终点
{
"ceratedDate": "2012-12-12",
"modifiedDate": "2012-12-13",
"profile": {
"firstName": "John",
"lastName": "Wick"
}
}
我希望它的工作方式是将createdDate和modifiedDate保存到Patient Table,并将firstName和lastName保存到Profile Table。
为什么不起作用?我必须做任何额外的工作才能让它工作吗?当获取它时,它只返回没有配置文件对象的Patient模型。我想这是同样的问题吗?
感谢您的帮助!
LoopBack不支持相关模型的批量更新。您必须单独更新患者/档案模型。欢迎在上打开问题https://github.com/strongloop/loopback-datasource-juggler/issues.