improvement: add prepend?: true option to add_change

This commit is contained in:
Zach Daniel 2024-01-20 21:48:57 -05:00
parent fc522ff6c5
commit 5af5702efb
2 changed files with 22 additions and 1 deletions

View file

@ -430,6 +430,8 @@ defmodule Ash.Actions.Read.Relationships do
related_query,
Ash.context_to_opts(related_query.context),
fn ->
IO.inspect(Ash.DataLayer.in_transaction?(related_query.resource))
IO.inspect(self(), label: "fetch pid")
result =
related_query
|> select_destination_attribute(relationship)
@ -438,7 +440,17 @@ defmodule Ash.Actions.Read.Relationships do
|> Ash.Query.set_context(%{
accessing_from: %{source: relationship.source, name: relationship.name}
})
|> tap(fn thing ->
if Application.get_env(:foo, :bar) do
IO.inspect(thing)
end
end)
|> Ash.Actions.Read.unpaginated_read()
|> tap(fn thing ->
if Application.get_env(:foo, :bar) do
IO.inspect(thing)
end
end)
{relationship, related_query, result}
end

View file

@ -190,8 +190,17 @@ defmodule Ash.Resource.Builder do
module -> {module, []}
end
type =
if opts[:prepend?] do
:prepend
else
:append
end
opts = Keyword.delete(opts, :prepend?)
with {:ok, change} <- build_change(ref, opts) do
Transformer.add_entity(dsl_state, [:changes], change, type: :append)
Transformer.add_entity(dsl_state, [:changes], change, type: type)
end
end