State transitions do not persist to DB in ActiveRecord models
Reported by Jaryl Sim | April 12th, 2009 @ 05:07 PM
foo.bar! does not persist to the database due to a failed validation. The documentation for the WriteState::aasm_write_state method indicates that update_attribute is being used to bypass validation, but this is not the case.
After calling write_attribute, save is being called to persist the changes. Since save does validation, this breaks the design of state transitions in AASM.
A proposed fix would be to call save(false) to skip validation, see pastie:
Comments and changes to this ticket
-
Hans Friedrich July 26th, 2010 @ 09:40 PM
- Milestone order changed from 0 to 0
Why was this reverted?
http://github.com/rubyist/aasm/commit/2d8887fdcf515eac2f18c534ab35c...
-
Jaryl Sim July 26th, 2010 @ 09:49 PM
@Hans I am thinking that the original author did not intend for invalid models to persist. Instead, they opted to fix the misleading comment.
-
sara ceejay August 14th, 2011 @ 03:56 PM
Very informative blog! These kind of post are always inspiring and I prefer to read quality content so I happy to find many good point here in the post, writing is simply great, thank you for the post. Camden Chronicle
-
Ralphlauren Boss December 19th, 2011 @ 03:57 PM
You have provided a great piece of information. I will definitely share it with my other friends. Keep up the good work, I would to stay in contact with your posts.
info@ralf(Ralphlauren).com
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.
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.