Bookshelf.js与目标模型数组中id的相关查询

时间:2015-12-07 06:13:15

标签: sql bookshelf.js knex.js

寻找一种方法来使用bookshelf.js withRelated来查找主键存在于外键数组中的相关项。

bookshelf.model( 'User', {
  tableName: 'users',
  organizations: function() {
      return this.hasMany(Organizations, 'team');
  },
});

bookshelf.model( 'Organization', {
  tableName: 'organizations',
  defaults: {
     team: [1, 2, 3]
 }
});

User.where({id: 1}).fetch({withRelated :['organizations']})
  .then(function(user) {
    //error
    // Unhandled rejection error: select "organizations".* from 
       "organizations" where "organizations"."team" in ($1) - malformed array literal 
});

0 个答案:

没有答案