Resource interactions
So my simple question is this, how/can one resource interact with another.
I have a "bank_account" and bank accounts can have "transactions" when a transaction is
pending=false
, which is set through the update :cleared
action, I want to then add or subtract the amount on that transaction from the bank_account balance. See pseudo code in image attached for what I am envisioning.
3 Replies
You probably want an afteraction hook there
```elixir
change fn changeset, ->
Ash.Changeset.after_action(changeset, fn changeset, result ->
# do your stuff here
end)
end
``
You can use
change to add pretty much arbitrary behavior to an action, and you can attach hooks for various lifecycle events, mainly
before_transaction -> before_action -> after_action -> after_transaction`more on lifecycle stuff here: https://ash-hq.org/docs/guides/ash/latest/topics/actions#create-update-destroy-actions
Okay, great. I'll try and take a look at that. Thank you very much. 🙂