Sequelize CheatSheet
Join Queries
First, assign the related table in the model, you can put it on bottom of model, before export function
User.hasMany(Post, {foreignKey: 'user_id'})
Post.belongsTo(User, {foreignKey: 'user_id'})
then you can call it using
Post.find({ where: { ...}, include: [User]})
Source:
Further reading:
- http://docs.sequelizejs.com/en/latest/docs/associations/#one-to-one-associations
- http://docs.sequelizejs.com/en/latest/docs/associations/#one-to-many-associations
- http://docs.sequelizejs.com/en/latest/docs/models-usage/#eager-loading