寻找一种方法来使用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
});