fix: RPCs not embedding correctly when using overloaded functions for computed relationships

This commit is contained in:
Laurence Isla
2023-10-02 16:00:33 -05:00
committed by GitHub
parent 4c44782d15
commit 910950dbac
7 changed files with 49 additions and 3 deletions
@@ -192,3 +192,29 @@ spec = describe "computed relationships" $ do
{"name":"Windows 10","computed_clients":{"name":"Microsoft"}}
]}
]|] { matchHeaders = [matchContentTypeJson] }
-- https://github.com/PostgREST/postgrest/issues/2963
context "can be defined using overloaded functions" $ do
it "tables" $ do
get "/items?select=*,computed_rel_overload(*)&limit=1"
`shouldRespondWith`
[json|
[{"id":1,"computed_rel_overload":[{"id":1}]}]
|] { matchHeaders = [matchContentTypeJson] }
get "/items2?select=*,computed_rel_overload(*)&limit=1"
`shouldRespondWith`
[json|
[{"id":1,"computed_rel_overload":[{"id":1},{"id":2}]}]
|] { matchHeaders = [matchContentTypeJson] }
it "rpc" $ do
get "/rpc/search?id=1&select=*,computed_rel_overload(*)"
`shouldRespondWith`
[json|
[{"id":1,"computed_rel_overload":[{"id":1}]}]
|] { matchHeaders = [matchContentTypeJson] }
get "/rpc/search2?id=1&select=*,computed_rel_overload(*)"
`shouldRespondWith`
[json|
[{"id":1,"computed_rel_overload":[{"id":1},{"id":2}]}]
|] { matchHeaders = [matchContentTypeJson] }
+15
View File
@@ -3456,3 +3456,18 @@ returns table(id int, val complex) as $$
union
select 3, row(0.3, 0.7)::complex as val;
$$ language sql;
create function computed_rel_overload(items) returns setof items2 as $$
select * from items2 limit 1
$$ language sql;
create function computed_rel_overload(items2) returns setof items2 as $$
select * from items2 limit 2
$$ language sql;
create function search2(id bigint) returns setof items2
language plpgsql
stable
as $$ begin
return query select items2.id from items2 where items2.id=search2.id;
end$$;