fix: nested empty embeds no longer return empty values and are correctly omitted
This commit is contained in:
committed by
Wolfgang Walther
parent
8d7d7e4112
commit
8f8dbd3425
@@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Fixed
|
||||
|
||||
- #3093, Nested empty embeds no longer show empty values and are correctly omitted - @laurenceisla
|
||||
|
||||
## [12.2.1] - 2024-06-27
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -622,7 +622,11 @@ generateRelSelectField (Node ReadPlan{relToParent=Just rel, select, relName, rel
|
||||
where
|
||||
rsSelName = fromMaybe relName relAlias
|
||||
rsEmbedMode = if relIsToOne rel then JsonObject else JsonArray
|
||||
rsEmptyEmbed = null select && null forest
|
||||
rsEmptyEmbed = hasOnlyNullEmbed (null select) forest
|
||||
hasOnlyNullEmbed = foldr checkIfNullEmbed
|
||||
checkIfNullEmbed :: ReadPlanTree -> Bool -> Bool
|
||||
checkIfNullEmbed (Node ReadPlan{select=s} f) isNullEmbed =
|
||||
isNullEmbed && hasOnlyNullEmbed (null s) f
|
||||
generateRelSelectField _ = Nothing
|
||||
|
||||
generateSpreadSelectFields :: ReadPlan -> [SpreadSelectField]
|
||||
|
||||
@@ -1218,6 +1218,20 @@ spec actualPgVersion = do
|
||||
[json|[{"id":1,"name":"Angela Martin"}]|]
|
||||
{ matchHeaders = [matchContentTypeJson] }
|
||||
|
||||
it "works on nested relationships" $ do
|
||||
get "/users?select=*,users_tasks(tasks(projects()))" `shouldRespondWith`
|
||||
[json| [{"id":1,"name":"Angela Martin"}, {"id":2,"name":"Michael Scott"}, {"id":3,"name":"Dwight Schrute"}]|]
|
||||
{ matchHeaders = [matchContentTypeJson] }
|
||||
get "/users?select=*,users_tasks!inner(tasks!inner(projects()))&users_tasks.tasks.id=eq.3" `shouldRespondWith`
|
||||
[json| [{"id":1,"name":"Angela Martin"}]|]
|
||||
{ matchHeaders = [matchContentTypeJson] }
|
||||
get "/users?select=*,tasks(projects(clients()),users_tasks())" `shouldRespondWith`
|
||||
[json| [{"id":1,"name":"Angela Martin"}, {"id":2,"name":"Michael Scott"}, {"id":3,"name":"Dwight Schrute"}]|]
|
||||
{ matchHeaders = [matchContentTypeJson] }
|
||||
get "/users?select=*,tasks!inner(projects(clients()),users_tasks(),name)&tasks.id=eq.3" `shouldRespondWith`
|
||||
[json| [{"id":1,"name":"Angela Martin","tasks":[{"name": "Design w10"}]}]|]
|
||||
{ matchHeaders = [matchContentTypeJson] }
|
||||
|
||||
context "empty root select" $
|
||||
it "gives all columns" $ do
|
||||
get "/projects?select=" `shouldRespondWith`
|
||||
@@ -1413,4 +1427,3 @@ spec actualPgVersion = do
|
||||
get "/infinite_recursion?select=*" `shouldRespondWith`
|
||||
[json|{"code":"42P17","message":"infinite recursion detected in rules for relation \"infinite_recursion\"","details":null,"hint":null}|]
|
||||
{ matchStatus = 500 }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user