loopback.js中基(抽象?)模型之间的关系

时间:2015-09-17 14:31:48

标签: node.js loopbackjs

我有一个名为Post的“抽象”模型,它是问题,答案和评论的基础模型。然后我想实现用户可以喜欢/不喜欢帖子,所以我建立了这种关系:

帐户:

  "relations": {
    "likes": {
      "type": "hasMany",
      "model": "Post",
      "foreignKey": "accountId",
      "keyThrough": "postId",
      "through": "Like"
    }
  }

发表:

  "relations": {
    "likes": {
      "type": "hasMany",
      "model": "Account",
      "foreignKey": "postId",
      "keyThrough": "accountId",
      "through": "Like"
    }
  }

像:

  "relations": {
    "post": {
      "type": "belongsTo",
      "model": "Post",
      "foreignKey": "postId"
    },
    "account": {
      "type": "belongsTo",
      "model": "Account",
      "foreignKey": "accountId"
    }
  }

现在我有制作喜欢的方法:

Question.likes.link({id: $scope.question.id, fk: Account.getCurrentId()},
        function successCb(value, responseHeaders){
          ...
        },
        function errorCb(error){
          ...
        }
      );

但是,在我的数据库中调用之后我遇到了这种情况:

[
  {
    "id": "55f9bc6d1cc13cf4378f42cd",
    "accountId": "55f7de1477d818c40f6646f2",
    "undefined": "55f95edfea24d97a1868f88e"
  }
]

为什么postId的键是未定义的?

0 个答案:

没有答案