Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

State change should not trigger callbacks

#19

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.

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

State: new
Milestone: none
Assigned to: Scott Barron Scott Barron

Activity

  1. Travis Tilley
    Travis Tilley

    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)
      end
    
      define_method("#{name.to_s}") do |*args|
        aasm_fire_event(name, false, *args)
      end
    

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

    October 24th, 2009 @ 01:34 AM

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.