Would be nice to use multiple callbacks in order to support things like Ecto.Multi. So instead of just having a :callback which needs to call :validate_state_transition which expects an Ecto.Changeset, you have :before_transition and an :after_transition.
This allows you to do
use EctoStateMachine,
states: [:initial, :confirmed],
events: [
[
name: :confirm,
from: [:inital],
to: :confirmed,
before_transition: fn(model, _params) -> Ecto.Changeset.change(model, expired_at: Ecto.DateTime.utc()),
after_transition: fn(changeset, params) do
Multi.new
|> Multi.update(changeset)
|> Multi.insert(TBD.changeset(%TBD{}, params)
end
]
]
Now you can call User.confirm(params) and the params supplied will get applied to the transition functions.
Would be nice to use multiple callbacks in order to support things like
Ecto.Multi. So instead of just having a :callback which needs to call :validate_state_transition which expects anEcto.Changeset, you have :before_transition and an :after_transition.This allows you to do
Now you can call
User.confirm(params)and the params supplied will get applied to the transition functions.