0

I have red the documentation of sequelize but could not get the idea/concept i wanted ,I don't want just one attribute to be shown. We have the following syntax to get the attributes we need

Model.findAll({
    attributes:['foo','bar]          
})

In my case I have many attributes in single table , I just want to hide one attribute.Is there any way in sequelize that we define the attribute which we don't want to see and get all other by default..

For Example....

    Model.findAll({
       attributes:hide foo , show all other attributes
})

AnyOne Can help..

1 Answer 1

2

You can use below syntax.

Model.findAll({
  attributes: {
    exclude: ['foo'] // hide this
  }
});

You can also exclude fields on model level by adding in their default scope like below.

const Model = sequelize.define('model',{
  secretColumn: Sequelize.STRING,
  //... and other columns
}, {
  defaultScope: {
    attributes: { exclude: ['secretColumn'] }
  }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.