AR field not updated automatically?

0 views
Skip to first unread message

Steve V

unread,
Sep 21, 2009, 1:18:06 AM9/21/09
to state-fu
I'm using 0.11.1, and it seems like the AR field for the machine is
not being updated at all as it is always nil. I have "machine
(:status)" defined, so according to the documentation I'm assuming
that my field "status_state" should be being automatically set. Is
there an option that is needed to do this?

Thanks,
Steve

Steve V

unread,
Sep 21, 2009, 10:46:12 AM9/21/09
to state-fu
Apparently reading correctly is helpful. #{machine}_field not _state.
Was stuck thinking in AASM which has the column state. Although it
does seem like the actual AR field is only set before being saved.
Should this maybe be populated when the object is instantiated?

Steve

David Lee

unread,
Sep 23, 2009, 4:53:49 AM9/23/09
to stat...@googlegroups.com
Hi Steve,

The field is updated when .state_fu is referenced - i.e., the state machine is instantiated when someone asks for it. This is done before creation via 'before_create :state_fu!', which instantiates all of an object's state machines, to ensure a default value is saved to the database (in the case of ActiveRecord models).

I chose not to initialize it until it is needed for performance reasons.

Does that answer your question?

cheers,
David Lee.
--
cheers,
David Lee
Reply all
Reply to author
Forward
0 new messages