Skip to content

Commit

Permalink
fix: properly load depended on fields for relationships even if `publ…
Browse files Browse the repository at this point in the history
…ic?: false`
  • Loading branch information
zachdaniel committed Apr 11, 2024
1 parent 0b79515 commit 752320c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/ash/actions/read/read.ex
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ defmodule Ash.Actions.Read do

defp source_fields(query) do
query
|> Ash.Query.accessing([:relationships])
|> Ash.Query.accessing([:relationships], false)
|> Enum.flat_map(fn name ->
case Ash.Resource.Info.relationship(query.resource, name) do
%{no_attributes?: true} ->
Expand Down
2 changes: 0 additions & 2 deletions lib/ash/code_interface.ex
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,6 @@ defmodule Ash.CodeInterface do
require Ash.Query
{filters, params} = Map.split(params, unquote(filter_keys))


query
|> Ash.Query.for_read(unquote(action.name), params, query_opts)
|> Ash.Query.filter(filters)
Expand Down Expand Up @@ -641,7 +640,6 @@ defmodule Ash.CodeInterface do
end
else
quote do

if opts[:stream?] do
Ash.stream!(query, Keyword.drop(opts, [:stream?, :stream_options]))
else
Expand Down
14 changes: 12 additions & 2 deletions lib/ash/query/query.ex
Original file line number Diff line number Diff line change
Expand Up @@ -996,10 +996,20 @@ defmodule Ash.Query do
Provide a list of field types to narrow down the returned results.
"""
def accessing(query, types \\ [:attributes, :relationships, :calculations, :aggregates]) do
def accessing(
query,
types \\ [:attributes, :relationships, :calculations, :aggregates],
only_public? \\ true
) do
query.resource
|> Ash.Resource.Info.fields(types)
|> Stream.filter(& &1.public?)
|> then(fn fields ->
if only_public? do
Stream.filter(fields, & &1.public?)
else
fields
end
end)
|> Stream.map(& &1.name)
|> Enum.filter(&loading?(query, &1))
end
Expand Down

0 comments on commit 752320c

Please sign in to comment.