Skip to content

Commit

Permalink
test: add test for relationship filter with parent(parent(field))
Browse files Browse the repository at this point in the history
  • Loading branch information
vonagam committed Jan 10, 2025
1 parent fbc4346 commit 265205c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
11 changes: 10 additions & 1 deletion test/rel_with_parent_filter_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule AshPostgres.RelWithParentFilterTest do
use AshPostgres.RepoCase, async: false

alias AshPostgres.Test.Author
alias AshPostgres.Test.{Author, Comedian, Joke}

require Ash.Query

Expand Down Expand Up @@ -75,4 +75,13 @@ defmodule AshPostgres.RelWithParentFilterTest do

assert length(authors) == 1
end

test "filter on relationship using double parent works as expected when loading relationship" do

Check failure on line 79 in test/rel_with_parent_filter_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (16) / mix test

test filter on relationship using double parent works as expected when loading relationship (AshPostgres.RelWithParentFilterTest)

Check failure on line 79 in test/rel_with_parent_filter_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (15) / mix test

test filter on relationship using double parent works as expected when loading relationship (AshPostgres.RelWithParentFilterTest)

Check failure on line 79 in test/rel_with_parent_filter_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (14) / mix test

test filter on relationship using double parent works as expected when loading relationship (AshPostgres.RelWithParentFilterTest)
commedian = Comedian.create!(%{name: "John"})
joke = Joke.create!(%{comedian_id: commedian.id})
joke_id = joke.id

commedian = Ash.load!(commedian, [:parent_parent_jokes])
assert [%{id: ^joke_id}] = commedian.parent_parent_jokes
end
end
4 changes: 4 additions & 0 deletions test/support/resources/comedian.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ defmodule AshPostgres.Test.Comedian do

relationships do
has_many(:jokes, AshPostgres.Test.Joke, public?: true)

has_many :parent_parent_jokes, AshPostgres.Test.Joke do
filter expr(exists(comedian, id == parent(parent(id))))
end
end

calculations do
Expand Down
8 changes: 8 additions & 0 deletions test/support/resources/joke.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ defmodule AshPostgres.Test.Joke do

actions do
defaults([:read])

create :create do
accept [:text, :is_good, :comedian_id]
end
end

code_interface do
define(:create)
end

postgres do
Expand Down

0 comments on commit 265205c

Please sign in to comment.