test: spread embed disambiguates recursive m2m

This commit is contained in:
steve-chavez
2022-11-18 18:11:14 -05:00
committed by Steve Chavez
parent 60c0c11c1d
commit 25f65065f4
4 changed files with 31 additions and 1 deletions
+2 -1
View File
@@ -9,8 +9,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- #1414, Add related orders - @steve-chavez
+ 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
- #1233, #1907, 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 a recursive m2m embed
+ Allows disambiguating an embed that has a many-to-many relationship using two foreign keys on a junction
### Fixed
@@ -109,6 +109,18 @@ spec =
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 "can disambiguate a recursive m2m with spread embeds" $ do
get "/posters?select=*,subscribers:subscriptions!subscribed(..posters!subscriber(*))&limit=1" `shouldRespondWith`
[json| [ {"id":1,"name":"Mark","subscribers":[{"id":3,"name":"Bill"}, {"id":4,"name":"Jeff"}]}]|]
{ matchStatus = 200
, matchHeaders = [matchContentTypeJson]
}
get "/posters?select=*,subscriptions!subscriber(..posters!subscribed(*))&limit=1" `shouldRespondWith`
[json| [{"id":1,"name":"Mark","subscriptions":[{"id":2,"name":"Elon"}]}]|]
{ matchStatus = 200
, matchHeaders = [matchContentTypeJson]
}
it "errs on an ambiguous embed that has two one-to-one relationships" $
get "/first?select=second(*)" `shouldRespondWith`
[json| {
+6
View File
@@ -832,3 +832,9 @@ INSERT INTO trash(id) VALUES (1), (2), (3);
TRUNCATE TABLE trash_details CASCADE;
INSERT INTO trash_details(id,jsonb_col) VALUES (1,'{"key": 10}'), (2,'{"key": 6}'), (3,'{"key": 8}');
TRUNCATE TABLE posters CASCADE;
INSERT INTO posters(id,name) VALUES (1,'Mark'), (2,'Elon'), (3,'Bill'), (4,'Jeff');
TRUNCATE TABLE subscriptions CASCADE;
INSERT INTO subscriptions(subscriber,subscribed) VALUES (3,1), (4,1), (1,2);
+11
View File
@@ -3026,3 +3026,14 @@ LANGUAGE sql
AS $$
select * from test.yards;
$$;
create table test.posters(
id int primary key,
name text
);
create table test.subscriptions(
subscriber int references test.posters(id),
subscribed int references test.posters(id),
primary key(subscriber, subscribed)
);