sbennett33
Hey all!
I have a resource called Assignment that’s backed by AshStateMachine and can go through several states: draft → assigned → closed → archived.
When an assignment is closed we need to perform a few side effects like triggering Notifiers or kicking off background jobs.
We’d like to allow users to archive an assignment that’s in the assigned state but we want to trigger all of the same side effects that happen when it gets closed (you can think of it like we want the assignment to go through the closed state before we archive it).
My initial thought was to add a before_action change on the archive action that checks the current state and conditionally calls the close action on the resource.
Is that the best way to “chain” actions? Is there a better way to conditionally force an action/state transition to happen before another one?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 1- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
zachdaniel
The
before_actionhook would likely be the first thing that I reach for, yes. You can do something like this: