#19 new
Pete P.

State change should not trigger callbacks

Reported by Pete P. | April 16th, 2009 @ 01:40 AM

Right now, AASM uses update_attribute to perform the state change. This avoids validation but does not avoid the other callbacks.

Ideally, the update should take place without using callbacks or the api should give the option to perform the update with the database or just update the attribute without saving.

The use case which this causes a problem is when you want to update the state in a callback. You would want to do this, particularly, if you are using AR's mass assignment. With the current implementation, if you were to update the state in a callback, you would end up with an infinite loop.

In rails, the only way to update a record without validations AND callbacks is to use the AR class method #update_all with conditions specifying just the single record you want to update.

Like I said, an alternative would be a method in the api that just updates the attribute in the AR object to the next state for the event and let's us handle the save manually.

Comments and changes to this ticket

  • Travis Tilley

    Travis Tilley October 24th, 2009 @ 01:34 AM

    events can be called with or without a bang to determine whether or not persistence should be used:

      define_method("#{name.to_s}!") do |*args|
        aasm_fire_event(name, true, *args)
      define_method("#{name.to_s}") do |*args|
        aasm_fire_event(name, false, *args)

    as for bypassing callbacks... i'm not sure that's wise for any scenario other than what you're describing.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Library for adding state machines to Ruby classes. Includes persistence layers for things like ActiveRecord. Formerly known as acts_as_state_machine.

People watching this ticket