pluginaweek / state_machine

Adds support for creating state machines for attributes on any Ruby class
http://www.pluginaweek.org
MIT License
3.74k stars 507 forks source link

Warning when using ActiveRecord and defaults are the same #285

Open devdazed opened 10 years ago

devdazed commented 10 years ago

getting the warning

Both MyModel and its :my_machine machine have defined a different default for "my_state". Use only one or the other for defining defaults to avoid unexpected behaviors.

when setting values for the default as such

state_machine :my_machine, :initial => :my_state, :namespace => 'the_name' do
  state :my_state, :value => 0
  state :my_other_state, :value => 1
end

In this case the database default for the model is 0. Upon further inspection, state machine is attempting to compare the string my_state with the model default of 0 rather than using the value specified for the state name.