Skip to content

Commit

Permalink
fix: add opts to all Ash.load calls (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
barnabasJ authored Nov 24, 2024
1 parent 67c35c1 commit 718f431
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
44 changes: 33 additions & 11 deletions lib/ash_json_api/controllers/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,13 @@ defmodule AshJsonApi.Controllers.Helpers do

with {:ok, result} <- Ash.run_action(action_input),
{:ok, result} <-
Ash.load(result, fields(request, request.resource), reuse_values?: true),
{:ok, result} <- Ash.load(result, request.includes_keyword) do
Ash.load(
result,
fields(request, request.resource),
Request.load_opts(request, reuse_values?: true)
),
{:ok, result} <-
Ash.load(result, request.includes_keyword, Request.load_opts(request)) do
Request.assign(request, :result, result)
else
{:error, error} ->
Expand Down Expand Up @@ -222,11 +227,16 @@ defmodule AshJsonApi.Controllers.Helpers do

with {:ok, result} <- Ash.run_action(action_input),
{:ok, result} <-
Ash.load(result, fields(request, request.resource), reuse_values?: true),
Ash.load(
result,
fields(request, request.resource),
Request.load_opts(request, reuse_values?: true)
),
{:ok, result} <-
Ash.load(
result,
request.includes_keyword || []
request.includes_keyword || [],
Request.load_opts(request)
) do
Request.assign(request, :result, result)
else
Expand Down Expand Up @@ -302,11 +312,16 @@ defmodule AshJsonApi.Controllers.Helpers do

with {:ok, result} <- Ash.run_action(action_input),
{:ok, result} <-
Ash.load(result, fields(request, request.resource), reuse_values?: true),
Ash.load(
result,
fields(request, request.resource),
Request.load_opts(request, reuse_values?: true)
),
{:ok, result} <-
Ash.load(
result,
request.includes_keyword || []
request.includes_keyword || [],
Request.load_opts(request)
) do
Request.assign(request, :result, result)
else
Expand Down Expand Up @@ -418,7 +433,7 @@ defmodule AshJsonApi.Controllers.Helpers do
|> case do
{:ok, record} ->
record
|> Ash.load(fields(request, request.resource), Request.opts(request))
|> Ash.load(fields(request, request.resource), Request.load_opts(request))
|> case do
{:ok, updated} ->
request
Expand Down Expand Up @@ -454,11 +469,16 @@ defmodule AshJsonApi.Controllers.Helpers do

with {:ok, result} <- Ash.run_action(action_input),
{:ok, result} <-
Ash.load(result, fields(request, request.resource), reuse_values?: true),
Ash.load(
result,
fields(request, request.resource),
Request.load_opts(request, reuse_values?: true)
),
{:ok, result} <-
Ash.load(
result,
request.includes_keyword || []
request.includes_keyword || [],
Request.load_opts(request)
) do
Request.assign(request, :result, result)
else
Expand Down Expand Up @@ -624,8 +644,10 @@ defmodule AshJsonApi.Controllers.Helpers do
end

with {:ok, result} <- Ash.run_action(action_input),
{:ok, result} <- Ash.load(result, load_lazy, reuse_values?: true),
{:ok, result} <- Ash.load(result, load) do
{:ok, result} <-
Ash.load(result, load_lazy, Request.load_opts(request, reuse_values?: true)),
{:ok, result} <-
Ash.load(result, load, Request.load_opts(request)) do
request
|> Request.assign(:result, result)
|> Request.assign(:record_from_path, result)
Expand Down
7 changes: 7 additions & 0 deletions lib/ash_json_api/request.ex
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ defmodule AshJsonApi.Request do
]
end

def load_opts(request, merge) do
Keyword.merge(
load_opts(request),
merge
)
end

def opts(request, merge \\ []) do
page_params = Map.get(request.assigns, :page)

Expand Down

0 comments on commit 718f431

Please sign in to comment.