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
callbacks and validations #28
Comments
To me, this is expected behavior. By defining a validation for the :second state, you’re indicating that any object in that state must pass that validation. As a result, when you attempt to transition from :first to :second via :boom, the validations for :second will be run. Can you expand on this bug? |
qoobaa commented The problem was, that I had to check if the transition is valid or not in associated model validation. I tried to find a workaround, for instance to call a method in associated model after valid transition, but in this case it’s impossible. I’ve also tried to use after_update callback: @@@ Ruby If transition fails, exception is thrown and transaction is rolled back. That’s enough for me at the moment. |
qoobaa commented Formatting problems, once again: The problem was, that I had to check if the transition is valid or not in associated model validation. I tried to find a workaround, for instance to call a method in associated model after valid transition, but in this case it’s impossible. I’ve also tried to use after_update callback: @@@ ruby ... but it doesn’t work at all. Finally I use event methods with bangs to check the transition: @@@ ruby If transition fails, exception is thrown and transaction is rolled back. That’s enough for me at the moment. |
If you need to do validation on the availability of an event, you can use something like: @@@ ruby You can see all of the various instance methods that are generated for an Event in the docs. They are currently:
Also, the latest updates on github might help you, specifically the attribute-based events: http://github.com/pluginaweek/state_machine/commit/2122d327aa835d47a71ff3bd750cfaa525e0cbb5 Feel free to re-open the ticket if you have additional feedback. |
qoobaa opened this issue
@@@ ruby
state_machine :initial => :first do
event :boom
transition :first => :second
end
state :second
validate :something # validation fails
end
after_transition :boom, :do => lambda { puts "BOOM!!!" }
@@@
result:
@@@
I think it’s not expected behavior, it causes a lot of problems in my app.
original LH ticket
This ticket has 0 attachment(s).
The text was updated successfully, but these errors were encountered: