Skip to content

Commit 3f00dcb

Browse files
authored
test: add failing test to demonstrate error using ref (#282)
Filtering on ref in this manner worked up until Ash 3.0. Now, it gives the following error: 1) test filter with ref (AshPostgres.FilterTest) test/filter_test.exs:1076 ** (FunctionClauseError) no function clause matching in Ash.Filter.check_filterable/2 The following arguments were given to Ash.Filter.check_filterable/2: # 1 AshPostgres.Test.Organization # 2 :id Attempted function clauses (showing 2 out of 2): defp check_filterable(_resource, []) defp check_filterable(resource, [relationship | rest]) code: |> Ash.Query.filter(^ref(:id, [:posts, :comments]) == ^comment.id) stacktrace: (ash 3.0.1) lib/ash/filter/filter.ex:2944: Ash.Filter.check_filterable/2 (ash 3.0.1) lib/ash/filter/filter.ex:2933: anonymous fn/2 in Ash.Filter.validate_filterable_relationship_paths/2 (elixir 1.16.2) lib/enum.ex:4316: Enum.find_value_list/3 (ash 3.0.1) lib/ash/filter/filter.ex:2923: Ash.Filter.validate_refs/3 (ash 3.0.1) lib/ash/filter/filter.ex:3015: Ash.Filter.resolve_call/2 (ash 3.0.1) lib/ash/filter/filter.ex:2489: Ash.Filter.add_expression_part/3 (ash 3.0.1) lib/ash/filter/filter.ex:2427: anonymous fn/3 in Ash.Filter.parse_expression/2 (elixir 1.16.2) lib/enum.ex:4839: Enumerable.List.reduce/3 (elixir 1.16.2) lib/enum.ex:2582: Enum.reduce_while/3 (ash 3.0.1) lib/ash/filter/filter.ex:334: Ash.Filter.parse/3 (ash 3.0.1) lib/ash/query/query.ex:2574: Ash.Query.do_filter/3 test/filter_test.exs:1095: (test)
1 parent 6d82579 commit 3f00dcb

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

test/filter_test.exs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
defmodule AshPostgres.FilterTest do
2-
alias AshPostgres.Test.Organization
32
use AshPostgres.RepoCase, async: false
4-
alias AshPostgres.Test.{Author, Comment, Post}
3+
4+
alias AshPostgres.Test.{Author, Comment, Post, Organization}
55
alias AshPostgres.Test.ComplexCalculations.{Channel, ChannelMember}
66

77
require Ash.Query
8+
import Ash.Expr
89

910
describe "with no filter applied" do
1011
test "with no data" do
@@ -1070,4 +1071,29 @@ defmodule AshPostgres.FilterTest do
10701071
)
10711072
|> Ash.read!()
10721073
end
1074+
1075+
test "filter with ref" do
1076+
organization =
1077+
Organization
1078+
|> Ash.Changeset.for_create(:create, %{name: "foo"})
1079+
|> Ash.create!()
1080+
1081+
post =
1082+
Post
1083+
|> Ash.Changeset.for_create(:create, %{organization_id: organization.id})
1084+
|> Ash.create!()
1085+
1086+
comment =
1087+
Comment
1088+
|> Ash.Changeset.for_create(:create, %{title: "not match"})
1089+
|> Ash.Changeset.manage_relationship(:post, post, type: :append_and_remove)
1090+
|> Ash.create!()
1091+
1092+
fetched_org =
1093+
Organization
1094+
|> Ash.Query.filter(^ref(:id, [:posts, :comments]) == ^comment.id)
1095+
|> Ash.read_one!()
1096+
1097+
assert fetched_org.id == organization.id
1098+
end
10731099
end

0 commit comments

Comments
 (0)