-
Notifications
You must be signed in to change notification settings - Fork 82
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 for Implicit Event Transitions #47
Comments
Any news? :-) |
I'd love to know the answer too. It's not clear if the lack of callback firing is a bug or an intended feature! |
This is a big one for me. To my mind, the callbacks should be triggered regardless of the way in which the state changes, be it events or setting the state manually. |
Doing a little hunting around and it seems that this might be 'by design' in the upstream https://github.com/state-machines/state_machines/blob/master/lib/state_machines/transition.rb#L2 When calling the simple I'd be interested in @rosskevin and @seuros thoughts on this - should we upstream the idea? Is it likely to be something we'd want to see in the core? |
bump. ran into this just now |
Bump. Me too. |
I ran into this as well, and found it quite confusing. I can see it not being as simple though as just having However the current behaviour of having multiple ways to change Possible improvements I can imagine to this might be:
There's probably other options as well. If any of these options was implemented it could be made opt-in to avoid breaking existing code. I'm happy to help with improving this but would need some guidance as to what approach would be preferred for improving this. |
What value would this have? I think it would be best to avoid setting state directly. Instead, do as the documentation suggests, and name the event to trigger the transition: vehicle.state_event = "ignite"
vehicle.save
...
vehicle.ignite
...
vehicle.fire_events(:ignite) The one example in the README that shows setting state directly has the following comment, indicating that this is skipping the state_machine # Skipping state_machine and writing to attributes directly
vehicle.state = "parked" It feels like to me there are valid reasons for setting state (e.g. test setup, scripting such as in seeds.rb, resetting state of an object from console, trap doors for admin overrides to go around state_machine), but it shouldn't be encouraged. |
Hi! I've noticed that callbacks for implicit event transitions don't work.
Example:
and now
but
Is there any solution to enable callbacks using normal assignment of the data (without using events)?
Gems:
Rails 5.0
state_machines-activerecord 0.4.0
The text was updated successfully, but these errors were encountered: