fix: embedding computed with normal relationship

This commit is contained in:
steve-chavez
2022-10-27 13:49:53 -05:00
committed by Steve Chavez
parent 5d126bf0a3
commit 45e7aac218
5 changed files with 34 additions and 9 deletions
@@ -136,3 +136,18 @@ spec = describe "computed relationships" $ do
get "/fee?select=*,jsbaz(*,johnsmith(*, fee(*)))"
`shouldRespondWith`
[json|[]|] { matchHeaders = [matchContentTypeJson] }
it "creates queries with the right aliasing when following a normal embed" $ do
get "/projects?select=name,clients(name,computed_projects(name))&limit=1"
`shouldRespondWith`
[json|
[{"name":"Windows 7","clients":{"name":"Microsoft","computed_projects":{"name":"Windows 7"}}}]
|] { matchHeaders = [matchContentTypeJson] }
get "/clients?select=name,projects(name,computed_clients(name))&limit=1"
`shouldRespondWith`
[json|[
{"name":"Microsoft","projects":[
{"name":"Windows 7","computed_clients":{"name":"Microsoft"}},
{"name":"Windows 10","computed_clients":{"name":"Microsoft"}}
]}
]|] { matchHeaders = [matchContentTypeJson] }
+8
View File
@@ -2910,3 +2910,11 @@ create trigger ins instead of insert on with_multiple_pks
-- issue https://github.com/PostgREST/postgrest/issues/2283
create view self_recursive_view as table projects;
create or replace view self_recursive_view as table self_recursive_view;
CREATE FUNCTION test.computed_clients(test.projects) RETURNS SETOF test.clients ROWS 1 AS $$
SELECT * FROM test.clients WHERE id = $1.client_id;
$$ LANGUAGE sql STABLE;
CREATE FUNCTION test.computed_projects(test.clients) RETURNS SETOF test.projects ROWS 1 AS $$
SELECT * FROM test.projects WHERE client_id = $1.id;
$$ LANGUAGE sql STABLE;