fix: aliasing on computed rels

This commit is contained in:
steve-chavez
2022-10-19 19:49:43 -05:00
committed by Steve Chavez
parent c8b39c6cde
commit 7ace8ace49
6 changed files with 56 additions and 15 deletions
@@ -107,3 +107,12 @@ spec = describe "computed relationships" $ do
get "/second_1?select=*,first_1(*)"
`shouldRespondWith`
[json|[]|] { matchHeaders = [matchContentTypeJson] }
-- https://github.com/PostgREST/postgrest/issues/2455
it "creates queries with the right aliasing" $ do
get "/fee?select=*,jsbaz(*,janedoe(*))"
`shouldRespondWith`
[json|[]|] { matchHeaders = [matchContentTypeJson] }
get "/fee?select=*,jsbaz(*,johnsmith(*, fee(*)))"
`shouldRespondWith`
[json|[]|] { matchHeaders = [matchContentTypeJson] }
+4
View File
@@ -210,6 +210,10 @@ GRANT ALL ON TABLE
, second
, first_1
, second_1
, fee
, baz
, janedoe
, johnsmith
TO postgrest_test_anonymous;
GRANT INSERT ON TABLE insertonly TO postgrest_test_anonymous;
+26
View File
@@ -2836,3 +2836,29 @@ $$ LANGUAGE sql STABLE ROWS 1;
CREATE FUNCTION test.first_1(test.second_1) RETURNS SETOF test.first_1 AS $$
SELECT * FROM test.first_1 WHERE second_id_1 = $1.id;
$$ LANGUAGE sql STABLE ROWS 1;
create table fee (
fee_id int primary key
);
create table baz (
baz_id int primary key
);
create table janedoe (
janedoe_id int primary key,
baz_id int references baz(baz_id)
);
create table johnsmith (
johnsmith_id int primary key,
fee_id int references fee(fee_id),
baz_id int references baz(baz_id)
);
create or replace function jsbaz(fee) returns setof baz as $$
select b.*
from baz b
join johnsmith js on js.baz_id = b.baz_id
where js.fee_id = $1.fee_id
$$ stable language sql;