Wednesday, 7 June 2017

loopback foreignKey as string with mysql

I'm having some trouble with loopback.

I'm trying to set a HasMany relationship with a foreignKey as STRING. But it does not seem to work properly.

TABLE_A

  • id
  • code_a(string)
  • label_a(string)

TABLE_B

  • id
  • code_b(string)
  • label_b(string)
  • code_a(string)

So it look like this:

TABLE_A

{
  "name": "TABLE_A",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "label_a": {
      "type": "string"
    },
    "code_a": {
      "type": "string"
    }
  },
  "validations": [],
  "relations": {
    "tablebs": {
      "type": "hasMany",
      "model": "TABLE_B",
      "foreignKey": "code_a"
    }
  },
  "acls": [],
  "methods": {}
}

TABLE B

{
  "name": "TABLE_B",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "label_b": {
      "type": "string"
    },
    "code_b": {
      "type": "string"
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": {}
}



via Théophile Hemachandra

No comments:

Post a Comment