@@ -2,6 +2,7 @@ defmodule AshPostgres.RelWithParentFilterTest do
2
2
use AshPostgres.RepoCase , async: false
3
3
4
4
alias AshPostgres.Test.Author
5
+ alias AshPostgres.Test.Post
5
6
6
7
require Ash.Query
7
8
@@ -75,4 +76,49 @@ defmodule AshPostgres.RelWithParentFilterTest do
75
76
76
77
assert length ( authors ) == 1
77
78
end
79
+
80
+ test "can stack parents" do
81
+ author =
82
+ Author
83
+ |> Ash.Changeset . for_create ( :create , % {
84
+ first_name: "abc"
85
+ } )
86
+ |> Ash . create! ( )
87
+
88
+ Post
89
+ |> Ash.Changeset . for_create ( :create , % { title: "the one" , author_id: author . id } )
90
+ |> Ash . create! ( )
91
+
92
+ assert % { author_from_exists: author_from_exists } =
93
+ Post
94
+ |> Ash.Query . for_read ( :read )
95
+ |> Ash.Query . filter ( title == "the one" )
96
+ |> Ash.Query . load ( :author_from_exists )
97
+ |> Ash.Query . limit ( 1 )
98
+ |> Ash . read_one! ( )
99
+
100
+ assert author_from_exists . id == author . id
101
+ end
102
+
103
+ test "can filter with stack parents" do
104
+ author =
105
+ Author
106
+ |> Ash.Changeset . for_create ( :create , % {
107
+ first_name: "abc"
108
+ } )
109
+ |> Ash . create! ( )
110
+
111
+ Post
112
+ |> Ash.Changeset . for_create ( :create , % { title: "the one" , author_id: author . id } )
113
+ |> Ash . create! ( )
114
+
115
+ assert % { author_from_exists: author_from_exists } =
116
+ Post
117
+ |> Ash.Query . for_read ( :read )
118
+ |> Ash.Query . filter ( author_from_exists . first_name == "abc" )
119
+ |> Ash.Query . load ( :author_from_exists )
120
+ |> Ash . read_one! ( )
121
+
122
+ assert author_from_exists . id == author . id
123
+ end
78
124
end
0 commit comments