Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
961 views
Welcome To Ask or Share your Answers For Others

1 Answer

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}} })


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...