Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test for relationship filter with parent(parent(field)) #457

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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 @@

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 All @@ -40,7 +44,7 @@
end
end

defmodule AshPostgres.Test.Comedian.HasJokes do

Check warning on line 47 in test/support/resources/comedian.ex

View workflow job for this annotation

GitHub Actions / ash-ci (16) / mix credo --strict

Modules should have a @moduledoc tag.

Check warning on line 47 in test/support/resources/comedian.ex

View workflow job for this annotation

GitHub Actions / ash-ci (15) / mix credo --strict

Modules should have a @moduledoc tag.

Check warning on line 47 in test/support/resources/comedian.ex

View workflow job for this annotation

GitHub Actions / ash-ci (14) / mix credo --strict

Modules should have a @moduledoc tag.
use Ash.Resource.Calculation

@impl true
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
Loading