Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- //includes the cross-reference table to join the schools with parents
- include: [
- { model: db.parentSchools },
- {
- model: db.schools, as: "schools",
- where: {
- [Op.eq]: [{ name: req.params.school }]
- }
- }
- ]
- }
- ).then(function (results) {
- res.json(results);
- console.log("parents for a school ", results);
- })
- Parent.belongsToMany(models.schools, {
- as: "schools",
- through: "parentSchools",
- foreignKey: "parentId"
- });
- };
- // a school belongs to many parents
- School.belongsToMany(models.parents, {
- as: "parents",
- // cross-reference table because a parent can have many schools as well
- through: "parentSchools",
- foreignKey: "schoolId"
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement