代码之家  ›  专栏  ›  技术社区  ›  Traveling Tech Guy

如何在环回中向现有表添加列

  •  0
  • Traveling Tech Guy  · 技术社区  · 6 年前

    我想在它们之间添加一个关系:Item->哈索内->政策

    我将此添加到Item.json:

    "relations": {
        "policy": {
          "type": "hasOne",
          "model": "Policy",
          "foreignKey": "policyId"
        }
    

    这是Policy.json

    "relations": {
        "item": {
          "type": "belongsTo",
          "model": "Item",
          "foreignKey": "policyId"
        }
    }
    

    autoregenerate 会注意到存在的差异,并向表中添加一个额外的列。相反,我得到了一个错误:

    (node:216) UnhandledPromiseRejectionWarning: RequestError: Invalid column name 'policyId'.
        at handleError (C:\Users\user\Project\MyProject\node_modules\loopback-connector-mssql\node_modules\mssql\lib\tedious.js:519:15)
    

    我认为这意味着我错过了一些东西。当然,Item表中没有创建额外的列。

    我需要做什么来启动要添加的列,还是需要手动执行此操作?

    1 回复  |  直到 6 年前
        1
  •  1
  •   IftekharDani    6 年前

    如果你建立了 policy item 那么你应该在 项目 模型。

    :

    UserFollower User 如果我们需要创造 EndUser 关系 用户跟随者 用户跟随者

    "properties": {
            "followee": {
                "type": "string",
                "required": true
            },
            "follower": {
                "type": "string",
                "required": true
            }
        },
      "relations": {
            "enduser_followee": {
                "type": "belongsTo",
                "model": "EndUser",
                "foreignKey": "followee"
            }
        }
    

    根据您的要求,只需删除以下代码 Policy.json

    "relations": {
        "item": {
          "type": "belongsTo",
          "model": "Item",
          "foreignKey": "policyId"
        }
    }