环回模型关系没有正确保存?

时间:2015-02-13 02:23:44

标签: mysql rest loopbackjs strongloop database-relations

患者模型

{
  "name": "Patient",
  "base": "PersistedModel",
  "idInjection": true,
  "properties": {
    "createdDate": {
      "type": "date"
    }
  },
  "validations": [],
  "relations": {
    "profile": {
      "type": "hasOne",
      "model": "Profile",
      "foreignKey": "profileID"
    }
  },
  "acls": [],
  "methods": []
}

PATIENT TABLE

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": []
}

PROFILE TABLE

id (INT)
firstName (VARCHAR)
lastName (VARCHAR)

问:当我保存模型时,我在/ api / patients / endpoint

后面进行POST
{
  "ceratedDate": "2012-12-12",
  "modifiedDate": "2012-12-13",
  "profile": {
    "firstName": "John",
    "lastName": "Wick"
  }
}

我期望它的工作方式是将createdDate和modifiedDate保存到Patient Table并将firstName和lastName保存到Profile Table。

为什么这不起作用? 我是否还需要做任何额外的工作才能让它发挥作用? 当GET它时,它只返回没有配置文件对象的Patient模型。我猜是同样的问题吗?

感谢任何帮助,谢谢!

1 个答案:

答案 0 :(得分:0)

LoopBack不支持相关模型的批量更新。您必须单独更新患者/个人资料模型。请随意在https://github.com/strongloop/loopback-datasource-juggler/issues打开问题。