Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用bookshelf.js多态关系进行反向关系查找_Javascript_Node.js_Orm_Bookshelf.js - Fatal编程技术网

Javascript 使用bookshelf.js多态关系进行反向关系查找

Javascript 使用bookshelf.js多态关系进行反向关系查找,javascript,node.js,orm,bookshelf.js,Javascript,Node.js,Orm,Bookshelf.js,我使用多态关系来允许帐户与两种不同的用户类型相关联:客户和员工。我对模型的定义如下: var Customer = bookshelf.Model.extend({ tableName: 'customer', accounts: function() { return this.morphMany(Account, 'concernable'); } }); var Staff = bookshelf.Model.extend({ tableName: 'staff'

我使用多态关系来允许
帐户
与两种不同的用户类型相关联:
客户
员工
。我对模型的定义如下:

var Customer = bookshelf.Model.extend({
  tableName: 'customer',
  accounts: function() {
    return this.morphMany(Account, 'concernable');
  }
});

var Staff = bookshelf.Model.extend({
  tableName: 'staff',
  accounts: function() {
    return this.morphMany(Account, 'concernable');
  }
});

var Account = bookshelf.Model.extend({
  tableName: 'account',
  concernable: function () {
    return this.morphTo('concernable', 'Staff', 'Customer');
  }
});
我的数据库是Postgres,我用于
帐户的模式是:

id (int)
business_id (int)
concernable_id (int)
concernable_type (string)
我试图做的是获取属于特定业务的所有帐户,并返回与这些帐户关联的客户。这与我在书架示例中看到的标准关系查找相反。以下是我在没有运气的情况下尝试过的:

   Account.where({
      business_id: filter.businessId,
      concernable_type: 'customer'
    })
    .fetchAll({
      withRelated: ['concernable']
    })
    .then((response) => {
      return reply.jsonapi(response, 'customer');
    });
我收到以下错误:
未找到目标多态模型
。如果我将
withRelated
更改为
customer
,则错误是在型号上找不到
customer

我想做的事可能吗


谢谢

你能解决这个问题吗?我也面临同样的问题。你能解决这个问题吗?我也面临同样的问题。