Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. {
  2. //includes the cross-reference table to join the schools with parents
  3. include: [
  4. { model: db.parentSchools },
  5. {
  6. model: db.schools, as: "schools",
  7. where: {
  8. [Op.eq]: [{ name: req.params.school }]
  9. }
  10. }
  11. ]
  12. }
  13. ).then(function (results) {
  14. res.json(results);
  15. console.log("parents for a school ", results);
  16. })
  17.  
  18. Parent.belongsToMany(models.schools, {
  19. as: "schools",
  20. through: "parentSchools",
  21. foreignKey: "parentId"
  22. });
  23. };
  24.  
  25. // a school belongs to many parents
  26. School.belongsToMany(models.parents, {
  27. as: "parents",
  28. // cross-reference table because a parent can have many schools as well
  29. through: "parentSchools",
  30. foreignKey: "schoolId"
  31. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement