Skip to content

Initial transition not created/callbacks not fired unless state_machine is touched #547

@mikebaldry

Description

@mikebaldry

The documentation suggests implementing like:

def state_machine
  @state_machine ||= OrderStateMachine.new(self, transition_class: OrderTransition,
                                                 association_name: :transitions,
                                                 initial_transition: true)
end

the initial transition is created and the callbacks then fired from this initializer, so if the state_machine isn't called after create of a model, this doesn't fire.

I'm not exactly sure of the scenarios state_machine isn't touched, if something happens internally with Statesman but not always or if it mostly happens that our code touches it in most cases, but we've had sporadic issues that has led me to add

after_create { state_machine }

to the models using Statesman, which appears to fix.

Should we need to do this, if so, could it be added to the documentation, if not, any ideas where we're going wrong?

Many thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions