-
Notifications
You must be signed in to change notification settings - Fork 64
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
Custom errors and valid property on Operations #534
Conversation
…od. Also added in a new add_error method for custom error messages not attached directly to attributes
@jwoertink Calling This is something that has tripped me up in rails before, and this PR implements the same thing. |
hmm 🤔 I guess I assumed you'd never call def valid?
return false if any_errors_detected?
#... other stuff it does
end |
maybe the |
Yup, exactly. Ok. I'll make that change and push it up. |
…se for you. If you're setting an error, it's not valid.
…tch the valid property. This is less of a short circuit and more of just error detection
Alright, so this doesn't really fix my original thought behind #529, but it does allow me to do some of what I intended by setting a custom error on operations. I'm thinking maybe in a future PR we could have some way to "halt" the entire chain of callbacks and such. Something that says "don't run any more callbacks, don't run any other validations... nothing... just stop and exit the operation". For now, this will be a good improvement. |
Fixes #529
This allows you to set custom errors not related to attributes. When you set an error message, the whole operation is no longer valid.
The main use case is when your operations (or save operations) need some external object, but that object itself may also not be valid.