1

PATIENT MODEL

{
  "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)

PROFILE MODEL

{
  "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)

Q: When I save the model, I POST following to /api/patients/ endpoint

{
  "ceratedDate": "2012-12-12",
  "modifiedDate": "2012-12-13",
  "profile": {
    "firstName": "John",
    "lastName": "Wick"
  }
}

The way I expect it to work is save createdDate and modifiedDate to Patient Table and save firstName and lastName to Profile Table.

Why is this not working ? Do I have to do any additional work to get it to work ? When GETting it it only returns Patient model without profile object in it. Is that the same issue I guess ?

Any help is appreciated, thanks !

Jordan Kasper
  • 13,153
  • 3
  • 36
  • 55
Dev Patel
  • 11
  • 1

1 Answers1

0

LoopBack doesn't support the batch update for the related models. You'll have to update Patient/Profile model separately. Feel free to open an issue at https://github.com/strongloop/loopback-datasource-juggler/issues.

Raymond Feng
  • 1,516
  • 9
  • 5
  • and how would that work if the relation is `"type": "embedsMany",` and the data source of the related resource is `"dataSource": "transient",`? I cannot seem to find out, how to create such objects with the `EntityClass.create()` method. – vanthome Apr 29 '16 at 06:01