Categories
JavaScript Answers

How to use an include with attributes with Node Sequelize?

Spread the love

To use an include with attributes with Node Sequelize, we set the attribute property.

For instance, we write

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

to call findAll to add the attributes property to exclude.

And we add include with the columns of Customer to include.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *