How to handle other resource notifications when inside a change?

Here is my change implementation:
defmodule Marketplace.Markets.Property.Offer.Actions.AcceptOffer.Changes.ChangePropertyToPending do
@moduledoc false

alias Marketplace.Markets.Property

use Ash.Resource.Change

@impl true
def change(changeset, _, _) do
Ash.Changeset.before_action(
changeset,
fn changeset ->
property_id = Ash.Changeset.get_data(changeset, :property_id)

change_property_to_pending!(property_id)

changeset
end,
append?: true
)
end

defp change_property_to_pending!(property_id) do
%{id: property_id} |> Property.get_any!() |> Property.update!(%{status: :pending})
end
end
defmodule Marketplace.Markets.Property.Offer.Actions.AcceptOffer.Changes.ChangePropertyToPending do
@moduledoc false

alias Marketplace.Markets.Property

use Ash.Resource.Change

@impl true
def change(changeset, _, _) do
Ash.Changeset.before_action(
changeset,
fn changeset ->
property_id = Ash.Changeset.get_data(changeset, :property_id)

change_property_to_pending!(property_id)

changeset
end,
append?: true
)
end

defp change_property_to_pending!(property_id) do
%{id: property_id} |> Property.get_any!() |> Property.update!(%{status: :pending})
end
end
This will run as a change of another resource, as you can see, it basically fetches the resource and updates its status. The problem is that the Property resource also has a pubsub notification for when the update action is called, and I will miss that notification and receive a warning since I'm not handling it here. My question is, how can I handle the update action notification inside that change?
2 Replies
ZachDaniel
ZachDaniel3y ago
You'd add the return_notifications?: true option to Property.update! and then you'd return {changeset, %{notifications: notifications}} from your before_action callback
Blibs
BlibsOP3y ago
Thanks Zack, that did it!

Did you find this page helpful?