sequelize Nested include with where clause sequelize Nested include with where clause express express

sequelize Nested include with where clause


You just need to the way to put where and you can also make option object and then pass it where you need

  • put where condition in every include if need
  • required true and false change joing rule

When an eager loaded model is filtered using include.where theninclude.required is implicitly set to true. This means that an innerjoin is done returning parent models with any matching children.

  • sequelize called it eager-loading visit for more detail eager-loading
var Table2 = require("../models/").table2; //and other model that u needvar option = {  limit: limit,  offset: offset,  order: "created_at DESC",  where: { deleted: 0 },  include: [    {      model: User,    },    {      model: Item,      required: true,      include: [        {          model: Image,        },      ],    },    {      model: Table2,      include: [        {          model: Table3,          where: { deleted: 0 },          include: [            {              model: Table4,              where: { deleted: 0 },            },          ],        },      ],    },  ],};Table1.findAndCountAll(option).then(function (results) {  res.json(results);});