diff --git a/test/aggregate_test.exs b/test/aggregate_test.exs index 167a00c9..91a422e8 100644 --- a/test/aggregate_test.exs +++ b/test/aggregate_test.exs @@ -1667,4 +1667,15 @@ defmodule AshSql.AggregateTest do Ash.Query.filter_input(AshPostgres.Test.StandupClub, filter) |> Ash.read!(load: [:punchline_count]) end + + @tag :regression + test "aggregates with modify_query works" do + assert_raise Ash.Error.Unknown, ~r/^modifying query!$/, fn -> + Post + |> Ash.Query.load([ + :count_comments_with_modify_query + ]) + |> Ash.read_one!() + end + end end diff --git a/test/support/resources/comment.ex b/test/support/resources/comment.ex index fe4a818e..517c42af 100644 --- a/test/support/resources/comment.ex +++ b/test/support/resources/comment.ex @@ -33,6 +33,10 @@ defmodule AshPostgres.Test.Comment do change(manage_relationship(:rating, :ratings, on_missing: :ignore, on_match: :create)) end + + read :with_modify_query do + modify_query({AshPostgres.Test.Comment.ModifyQuery, :modify, []}) + end end attributes do @@ -104,3 +108,14 @@ defmodule AshPostgres.Test.Comment do ) end end + +defmodule AshPostgres.Test.Comment.ModifyQuery do + @moduledoc """ + Raises when modifying query so we can assert + this code path is called. + """ + + def modify(_ash_query, _ecto_query) do + raise "modifying query!" + end +end diff --git a/test/support/resources/post.ex b/test/support/resources/post.ex index 94ab170e..79eddd34 100644 --- a/test/support/resources/post.ex +++ b/test/support/resources/post.ex @@ -1164,6 +1164,10 @@ defmodule AshPostgres.Test.Post do end first(:author_profile_description, :author, :description) + + count :count_comments_with_modify_query, :comments do + read_action(:with_modify_query) + end end end