From 60c0c11c1dbb206a206005affa15cae12facde48 Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Wed, 16 Nov 2022 22:53:42 -0500 Subject: [PATCH] test: spread embed disambiguates 2 fks on junction --- CHANGELOG.md | 1 + test/spec/Feature/Query/EmbedDisambiguationSpec.hs | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3667ae6b..3d4f2b5bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). + On a many-to-one or one-to-one relationship, you can order a parent by a child column `/projects?select=*,clients(*)&order=clients(name).desc.nullsfirst` - #1233, Allow spreading embedded resources - @steve-chavez + On a many-to-one or one-to-one relationship, you can unnest a json object with `/projects?select=*,..clients(client_name:name)` + + Allows disambiguating an embed that has a many-to-many relationship using two foreign keys on a junction ### Fixed diff --git a/test/spec/Feature/Query/EmbedDisambiguationSpec.hs b/test/spec/Feature/Query/EmbedDisambiguationSpec.hs index 50a56c283..8aee26530 100644 --- a/test/spec/Feature/Query/EmbedDisambiguationSpec.hs +++ b/test/spec/Feature/Query/EmbedDisambiguationSpec.hs @@ -68,10 +68,8 @@ spec = , matchHeaders = [matchContentTypeJson] } - it "errs when there are more than two fks on a junction table(currently impossible to disambiguate, only choice is to split the table)" $ + it "errs when there are more than two fks on a junction table but it can be disambiguated with spread embeds" $ do -- We have 4 possibilities for doing the junction JOIN here. - -- This could be solved by specifying two additional fks, like whatev_projects!fk1!fk2(*) - -- If the need arises this capability can be added later without causing a breaking change get "/whatev_sites?select=*,whatev_projects(*)" `shouldRespondWith` [json| { @@ -105,6 +103,11 @@ spec = { matchStatus = 300 , matchHeaders = [matchContentTypeJson] } + -- Each of those 4 possibilities can be done with spread embeds, by following the details in the error above + get "/whatev_sites?select=*,whatev_jobs!site_id_1(..whatev_projects!project_id_1(*))" `shouldRespondWith` [json|[]|] + get "/whatev_sites?select=*,whatev_jobs!site_id_1(..whatev_projects!project_id_2(*))" `shouldRespondWith` [json|[]|] + get "/whatev_sites?select=*,whatev_jobs!site_id_2(..whatev_projects!project_id_1(*))" `shouldRespondWith` [json|[]|] + get "/whatev_sites?select=*,whatev_jobs!site_id_2(..whatev_projects!project_id_2(*))" `shouldRespondWith` [json|[]|] it "errs on an ambiguous embed that has two one-to-one relationships" $ get "/first?select=second(*)" `shouldRespondWith`