after_action is not being triggered

I've tried several combinations, but it seems that the after_action callback is not being triggered. As a basic test, I added an IO.inspect expecting to see output in my IEx session, but nothing gets logged. Here's the code I'm using:
create :create do
primary? true
accept [:day, :start_time, :end_time, :subject_id, :group_id]

validate present([:day, :start_time, :end_time, :subject_id, :group_id])
validate {Calmecalli.Cohort.Class.Validations.NoTimeOverlap, []}

after_action(fn _changeset, result ->
result |> IO.inspect(label: "--- result")
{:ok, result}
end)
end
create :create do
primary? true
accept [:day, :start_time, :end_time, :subject_id, :group_id]

validate present([:day, :start_time, :end_time, :subject_id, :group_id])
validate {Calmecalli.Cohort.Class.Validations.NoTimeOverlap, []}

after_action(fn _changeset, result ->
result |> IO.inspect(label: "--- result")
{:ok, result}
end)
end
I'm calling it through the domain API using Calmecalli.Cohort.create_class!
2 Replies
ZachDaniel
ZachDaniel4mo ago
change after_action(...) Without the change in front it doesn't do anything
catrapato
catrapatoOP4mo ago
Thank you Zach! You're right! Just for reference, it looks like this is the correct way to call it:
change after_action(fn changeset, result, context ->
changeset |> IO.inspect(label: "--- changeset")
result |> IO.inspect(label: "--- result")
context |> IO.inspect(label: "--- context")
{:ok, result}
end)
change after_action(fn changeset, result, context ->
changeset |> IO.inspect(label: "--- changeset")
result |> IO.inspect(label: "--- result")
context |> IO.inspect(label: "--- context")
{:ok, result}
end)

Did you find this page helpful?