书架关系未按预期工作

Bookshelf relations aren't working as expected

我有4个表格简化如下:

表格

event:     id, location_id  
location:  id  
user:      id  
eventUser: event_id, user_id

关系

Event hasOne Location  
Event belongsToMany Users

Location belongsTo Event

User belongsToMany Events

EventUser belongsToMany Events  
EventUser belongsToMany Users

我想获取具有给定用户 ID 的位置的事件

我尝试过的一个例子:

EventUser.forge().where({user_id: 1}).fetchAll({withRelated: ['Event', 'Event.Location']})

但我无法return任何活动。

我的设置正确吗?

解决方案是

User.forge().where({id: 1}).fetchAll({withRelated: ['Event.Location']}) 然后向下钻取模型以获得我需要的东西。我以为我可以通过使用 EventUser 而不是 User 来减少一步。