I have three models user, tab, subscription. User can subscribe to many tabs and tab can have many subscribers.
user --* subscription *-- tab
Diagram from navicat
sequelize.define('subscription', {})
Tab.belongsToMany(User, { through: Subscription })
User.belongsToMany(Tab, { through: Subscription })
How do I get all subscribers for specific tab or all tabs which specific user subscribes to? I could do that in two queries but it have to be possible in one.
I have tried every possible combination of where, include, through which I would rather not share here. Every time I try to get access to subscription from any side I get subscription (subscriptions) is not associated to user.
I am trying to get something like this to work.
await Tab.findAll({
where: { name: ctx.params.tabname },
include: [{
model: Subscription,
through: {
where: { userUsername: ctx.params.username }
}
}]
})

user --* subscription *-- tab) and for the actual data I don't think they are relevant to problem I am facing.