I’m trying to have User.ex :create action to also create a default Calendar as soon as the user account is created. I thought passing actor in API.create will make it available in Calendar’s create action, but it doesn’t seem to work. Any idea why it’s not working?
<user create action>
change fn changeset, _ ->
Ash.Changeset.after_action(changeset, fn changeset, result ->
first_name = Ash.Changeset.get_attribute(changeset, :first_name)
IO.inspect(changeset.attributes, label: "changeset after action #########")
Tasks.Calendar
|> Ash.Changeset.for_create(:create, %{
calendar_name: "#{first_name}'s First Calendar",
created_by_id: Ash.Changeset.get_attribute(changeset, :id)
})
|> Tasks.create(actor: changeset.attributes)
|> IO.inspect(label: "calendar created #########")
end)
end
<calendar.ex>
create :create do
primary? true
change relate_actor(:created_by)
end
change fn changeset, _ ->
Ash.Changeset.after_action(changeset, fn changeset, result ->
calendar_changeset = Taskcalendars.Tasks.Calendar
|> Ash.Changeset.for_create(:create, %{calendar_name: "#{result.first_name}'s First Calendar"})
with {:ok, _calendar} <- Tasks.create(calendar_changeset, actor: result) do
{:ok, result
end
end)
end
Additionally, can you provide more information about the failure? Is there an error or backtrace for example?