Reputation: 672
I have two models, a Session and a Register, with a relation defined as follows:
Session.hasMany(Register, {
foreignKey: {
allowNull: false,
},
});
Register.belongsTo(Session);
I want to get a list of Sessions that the User has registered for, a Register has a foreign key with the User model. With only the UserId how would I get a list of Sessions that have a Register object created by the User?
Upvotes: 0
Views: 37
Reputation: 186
You can nest your include so that the user
model includes the register
which incldes the session
like the example below:
models.users.findOne({
where: {
email: data.email //or any other unique identifier
},
include: { model: models.register,
include: {model: models.sessions}}
})
Upvotes: 1