No actor in after_action context
I wondering what is the correct or recommended way of passing the actor down to a
But I'm not sure if I'm doing it properly and I'm missing something here?
after_changeafter_change callback. I've tried to use the contextcontext but the actoractor was always nilnil. I've ended up doing this: actions do
defaults [:read, :destroy]
create :create do
primary? true
accept [:name, :description, :metadata, :warehouse_id]
validate present(:name)
validate present(:warehouse_id)
change after_action(fn changeset, model, _context ->
# Access actor from the correct location in changeset.context
case get_in(changeset.context, [:private, :actor]) do
nil ->
{:error, "Actor context is required for creating initial model version"}
actor ->
# Create initial empty version
empty_model = %{
"entities" => [],
"entity_relationships" => [],
"metadata" => %{},
"version_notes" => "Initial empty model"
}
_version =
Astrobee.DataPipeline.ModelVersion
|> Ash.Changeset.for_create(:create, %{
ontology_id: model.id,
model: empty_model,
commit_message: "Initial version"
})
|> Ash.create!(actor: actor)
{:ok, model}
end
end)
end
end actions do
defaults [:read, :destroy]
create :create do
primary? true
accept [:name, :description, :metadata, :warehouse_id]
validate present(:name)
validate present(:warehouse_id)
change after_action(fn changeset, model, _context ->
# Access actor from the correct location in changeset.context
case get_in(changeset.context, [:private, :actor]) do
nil ->
{:error, "Actor context is required for creating initial model version"}
actor ->
# Create initial empty version
empty_model = %{
"entities" => [],
"entity_relationships" => [],
"metadata" => %{},
"version_notes" => "Initial empty model"
}
_version =
Astrobee.DataPipeline.ModelVersion
|> Ash.Changeset.for_create(:create, %{
ontology_id: model.id,
model: empty_model,
commit_message: "Initial version"
})
|> Ash.create!(actor: actor)
{:ok, model}
end
end)
end
endBut I'm not sure if I'm doing it properly and I'm missing something here?
