chore: run proper callback and test that we call the loading callback

This commit is contained in:
Zach Daniel 2024-08-20 10:25:50 -04:00
parent 51f57b6390
commit 48507eac13
3 changed files with 9 additions and 1 deletions

View file

@ -360,7 +360,7 @@ defmodule Ash.Actions.Read do
case query.action.manual do
{module, opts} ->
if module.has_load_relationships?() do
module.load_relationships(query, data, opts, lazy?)
module.load_relationships(query, data, opts, context, lazy?)
else
Ash.Actions.Read.Relationships.load(
data,

View file

@ -35,7 +35,12 @@ defmodule Ash.Resource.ManualRead do
defmacro __using__(_) do
quote do
@behaviour Ash.Resource.ManualRead
@before_compile Ash.Resource.ManualRead
end
end
defmacro __before_compile__(_) do
quote do
if Module.defines?(__MODULE__, {:load_relationships, 5}, :def) do
def has_load_relationships?, do: true
else

View file

@ -8,6 +8,7 @@ defmodule Ash.Test.Actions.ManualReadTest do
use Ash.Resource.ManualRead
def load_relationships(_, data, _, _, _) do
send(self(), :loading_relationships)
{:ok, data}
end
@ -109,6 +110,8 @@ defmodule Ash.Test.Actions.ManualReadTest do
Author
|> Ash.Query.for_read(:all)
|> Ash.read!()
assert_received :loading_relationships
end
test "Ash.Query.apply_to/2 can be used" do