Lazarus Rising
Lazarus Rising

Reputation: 2685

Configure default condition for sequelize queries

I have a column featured in most of the tables in a schema. I would like to make it the default behaviour of sequelize to filter every search by this parameter.

The obvious solution is to include the condition in every select. However, I am trying to find some other way, for example insert this condition in the model declaration (maybe using hooks). Also, ideally I would like for the condition to be default but optional. Ultimately I couldn't find a way to make it work.

I went through the sequelize documentation and couldn't find anything. Can such a thing be done in the model declaration or in some other level, before the actual query?

Upvotes: 1

Views: 1557

Answers (1)

MPastore
MPastore

Reputation: 36

I think that adding a defaultScope can help you. http://docs.sequelizejs.com/manual/tutorial/scopes.html

Upvotes: 2

Related Questions