Skip to content

Commit

Permalink
fix: properly match on return_query? option
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Dec 24, 2024
1 parent ac3b2f4 commit 1c470dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/ash.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1987,9 +1987,12 @@ defmodule Ash do
opts <- ReadOpts.to_options(opts),
{:ok, action} <- Ash.Helpers.get_action(query.resource, opts, :read, query.action),
{:ok, action} <- Ash.Helpers.pagination_check(action, query, opts),
{:ok, _resource} <- Ash.Domain.Info.resource(domain, query.resource),
{:ok, results} <- Ash.Actions.Read.run(query, action, opts) do
{:ok, results}
{:ok, _resource} <- Ash.Domain.Info.resource(domain, query.resource) do
case Ash.Actions.Read.run(query, action, opts) do
{:ok, results} -> {:ok, results}
{:ok, results, query} -> {:ok, results, query}
{:error, error} -> {:error, Ash.Error.to_error_class(error)}
end
else
{:error, error} ->
{:error, Ash.Error.to_error_class(error)}
Expand Down
7 changes: 7 additions & 0 deletions test/actions/read_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,13 @@ defmodule Ash.Test.Actions.ReadTest do
|> Ash.read()
end

test "return_query returns the query" do
assert {:ok, [_post], query} =
Post
|> Ash.Query.limit(1)
|> Ash.read(return_query?: true)
end

test "after action hooks are run" do
assert [%{__metadata__: %{prepared?: true}}, %{__metadata__: %{prepared?: true}}] =
Ash.read!(Post, action: :read_with_after_action)
Expand Down

0 comments on commit 1c470dd

Please sign in to comment.