File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
test/spec_compliance/fetching_data Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -577,6 +577,9 @@ defmodule AshJsonApi.Serializer do
577
577
type: AshJsonApi.Resource.Info . type ( destination )
578
578
} )
579
579
580
+ % { __linkage__: % { ^ name => [ ] } } ->
581
+ Map . put ( payload , :data , nil )
582
+
580
583
# There could be another case here if a bug in the system gave us a list
581
584
# of more than one shouldn't happen though
582
585
Original file line number Diff line number Diff line change @@ -160,6 +160,23 @@ defmodule AshJsonApiTest.FetchingData.InclusionOfRelatedResources do
160
160
# --------------------------
161
161
describe "include request parameter" do
162
162
@ describetag :spec_may
163
+ test "resource endpoint with include param of an empty to-one relationship (linkage)" do
164
+ post =
165
+ Post
166
+ |> Ash.Changeset . for_create ( :create , % { name: "foo" } )
167
+ |> Ash . create! ( )
168
+
169
+ assert % {
170
+ resp_body: % {
171
+ "data" => % {
172
+ "relationships" => % {
173
+ "author" => % { "data" => nil }
174
+ }
175
+ }
176
+ }
177
+ } = get ( Domain , "/posts/#{ post . id } /?include=author" , status: 200 )
178
+ end
179
+
163
180
test "resource endpoint with include param of to-one relationship (linkage)" do
164
181
# GET /posts/1?include=author
165
182
author =
@@ -212,6 +229,24 @@ defmodule AshJsonApiTest.FetchingData.InclusionOfRelatedResources do
212
229
end )
213
230
end
214
231
232
+ test "resource endpoint with include param of empty to-many relationship" do
233
+ # GET /posts/1?include=comments
234
+ post =
235
+ Post
236
+ |> Ash.Changeset . for_create ( :create , % { name: "foo" } )
237
+ |> Ash . create! ( )
238
+
239
+ assert % {
240
+ resp_body: % {
241
+ "data" => % {
242
+ "relationships" => % {
243
+ "comments" => % { "data" => [ ] }
244
+ }
245
+ }
246
+ }
247
+ } = get ( Domain , "/posts/#{ post . id } /?include=comments" , status: 200 )
248
+ end
249
+
215
250
test "resource endpoint with include param of to-many relationship" do
216
251
# GET /posts/1?include=comments
217
252
author =
You can’t perform that action at this time.
0 commit comments