I have the following three models
User
user_id
user_email
Group
group_id
group_name
GroupUser
group_user_id
user_id
group_id
How can I get group details(if it mapped with user ) while fetch User data ? Is there any Sequelize hasOne association through another table ?
There is currently no direct way in sequelize for what you are asking
ref https://github.com/sequelize/sequelize/issues/3845
but you can do
Group.belongsTo(GroupUser)
User.belongsTo(GroupUser)
GroupUser.hasOne(Group)
GroupUser.hasOne(User)
and do nested include (but this is not very efficient)
User.findAll({include : [{model:GroupUser, include :[{model : Group}]}]})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With