Loopbackjs 定义Loopback.io belongsTo关系的正确方法

Loopbackjs 定义Loopback.io belongsTo关系的正确方法,loopbackjs,Loopbackjs,我有一个简单的两个环回模型之间的关系: { "name": "ApiUser", "base": "PersistedModel", "idInjection": true, "options": { "postgresql": { "table": "users" }, "validateUpsert": true }, "properties": { "id": { "type": "string",

我有一个简单的两个环回模型之间的关系:

{
  "name": "ApiUser",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "postgresql": {
      "table": "users"
    },
    "validateUpsert": true
  },
  "properties": {
    "id": {
      "type": "string",
      "id": true,
      "required": true,
      "defaultFn": "uuid",
      "postgresql": {
        "dataType": "uuid"
      }
    },
    "email": {
        ...

当我运行自动迁移时,会创建shopifyaccount表,但它看起来很奇怪:

-------------------+---------+-------------------------------------------------------------

api|U键|文本|不为空

密码|文本|不为空

id | integer |非空默认nextval('shopificationaccount_id_seq'::regclass)

用户ID | uuid |

apiuserid|uuid|

索引:

“shopifyaccount_pkey”主键,btree(id)

为什么它要创建两个列,命名如下?即使我尝试指定foreignkey是“userid”,它仍然会创建apiuserid列。insert永远不会更新apiuserid列,但会更新userid列。然后在加入时,它将尝试使用apiuserid加入。我做错了什么?

所以。。。似乎需要在ApiUser和ShopifyAccount中的两个位置指定“foreignkey”:

{
  "name": "ApiUser",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "postgresql": {
      "table": "users"
    },
    "validateUpsert": true
  },
  "properties": {
    "id": {
      "type": "string",
      "id": true,
      "required": true,
      "defaultFn": "uuid",
      "postgresql": {
        "dataType": "uuid"
      }
    },
    "email": {
      "type": "string",
    ...
  "relations": {
    "shopifyAccounts": {
      "type": "hasOne",
      "model": "ShopifyAccount",
      "foreignKey": "userid"
    }
  },
  "acls": [],
  "methods": {}
}
  Column       |  Type   |                          Modifiers                          
{
  "name": "ApiUser",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "postgresql": {
      "table": "users"
    },
    "validateUpsert": true
  },
  "properties": {
    "id": {
      "type": "string",
      "id": true,
      "required": true,
      "defaultFn": "uuid",
      "postgresql": {
        "dataType": "uuid"
      }
    },
    "email": {
      "type": "string",
    ...
  "relations": {
    "shopifyAccounts": {
      "type": "hasOne",
      "model": "ShopifyAccount",
      "foreignKey": "userid"
    }
  },
  "acls": [],
  "methods": {}
}