'Sequelize filter the included tables by where

I am trying to findAll records included nested tables, but did not understand how could I filter included tables by where clause. Here are the words:

const players = await PlayerService.findPlayers({
    attributes: { exclude: ['password'] },
    include: [
      { all: true },
      {
        model: Team,
        as: 'captainTeams',
        attributes: {exclude: ['createdAt', 'updatedAt']}
      },
      {
        model: Team,
        as: 'teams',
        where: { type: 1 },
        required: true,
        through: {attributes: []},
        attributes: {exclude: ['createdAt', 'updatedAt']}
      }
    ]
  })

Here is the result:

enter image description here

If I delete where and required from including Team clause, here is the result:

enter image description here

I would like to filter teams.type=2. Could you help me ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source