pluginaweek/state_machine — Issue #164: Transition in after :save hook fails in DataMapper (works in a second save)
Author: rssaddict
Created: 2012-02-28 06:02:23+00:00
State: open

In our application, there are situations where we want to transition an object automatically from pending to accepted when it's created. I've tried to use a DataMapper after :create hook for this purpose, but for some reason the transition is not happening.

I moved the event into an after :save hook, which didn't help, except if you save the model a *second* time, in which case it does. I've created a Gist to reduce and demonstrate the problem: https://gist.github.com/1929985 (using the Vehicle example).

On first save, the state is still parked, but when saving again it transitions to idling. I've tried to dig through the code to see why this might be but I've been unable to come up with anything.