Skip to content

Commit 3a8b348

Browse files
committed
Add filtering test for through relationship
1 parent 82abf36 commit 3a8b348

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

test/filter/filter_test.exs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ defmodule Ash.Test.Filter.FilterTest do
237237
source_attribute: :author2_id,
238238
public?: true
239239

240+
has_many :source_post_links, PostLink, public?: true, destination_attribute: :source_post_id
241+
242+
has_many :same_related_posts, __MODULE__,
243+
through: [:source_post_links, :destination_post],
244+
public?: true
245+
240246
many_to_many :related_posts, __MODULE__,
241247
through: PostLink,
242248
source_attribute_on_join_resource: :source_post_id,
@@ -620,6 +626,13 @@ defmodule Ash.Test.Filter.FilterTest do
620626
|> Ash.read!()
621627
end
622628

629+
test "filtering on a through relationship", %{post4: %{id: post4_id}, post3: post3} do
630+
assert [%{id: ^post4_id}] =
631+
Post
632+
|> Ash.Query.filter(same_related_posts == ^post3.id)
633+
|> Ash.read!()
634+
end
635+
623636
test "relationship filters are honored when filtering on relationships", %{post2: post} do
624637
post = Ash.load!(post, [:special_author1, :author1])
625638

0 commit comments

Comments
 (0)