Skip to content

Warning when using ActiveRecord and defaults are the same #285

@devdazed

Description

@devdazed

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions