Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass in transaction object in custom validation? #4714

Closed
rbudiharso opened this issue Oct 23, 2015 · 2 comments

Comments

@rbudiharso
Copy link

commented Oct 23, 2015

How to pass in transaction object to be use in custom validation/model validation? hooks can access it via options object

sequelize.define('Model', {
  username: {
    type: DataType.STRING,
    validate: {
      customValidation: function(value) {
        // how to get transaction object here?
        // someQuery
      }
    }
  }
}, {
hooks: {
  beforeCreate: function(instance, options, fn) {
    // here we got options.transaction <== like this
  }
});
@janmeier

This comment has been minimized.

Copy link
Member

commented Oct 26, 2015

Hmm, I honestly don't think you should be able to access options in the validator for a single attribute. If you need to do any validations that are more involved I'd recommend before/afterValidate hooks

@rnemec

This comment has been minimized.

Copy link

commented Jan 5, 2017

I don't think running an additional query in a validator is involved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.