V
V
Vladimir Skibin2019-08-09 10:34:09
ORM
Vladimir Skibin, 2019-08-09 10:34:09

How to apply scope to update/save in sequelize when a value is returned as a result?

There are descriptions of scopes by roles in the model, for example, for the admin, we remove some fields from the result:

const scopes = {
  admins: {
    where: {
      role: ROLES.ADMIN
    },
    attributes: {
      exclude: ['xp', 'hp', 'mp', 'gold', 'lvl']
    }
  }
}

And when saving the model via user.save(params) - the model is returned already with these parameters, although, of course, if you use findOne or findAll with this scope, then the fields are not returned.
Now I'm working on a variant through the afterSave / afterUpdate hook in order to intercept and remove unnecessary things in it.
How can the scope be applied specifically to save / change?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question