sequelize where inside include code example

Example 1: sequelize include only

Payment.findAll({
    where: {
        DairyId: req.query.dairyid
    },
    attributes: {
        exclude: ['createdAt', 'updatedAt']
    },
    include: {
        model: Customer,
        attributes:['customerName', 'phoneNumber']
    }
})

Example 2: include with where clause in sequelize

Document.findAll({
where: {'$employee.manager.id$': id},
      include: [{
        model: models.Employee,
        required: true,
        as: 'employee',
        include: [{
          model: models.Manager,
          required: true,
          as: 'manager',
          where: { id: managerId },
        }],
      }],

Tags:

Misc Example