Add test for #996 embed bug when table name = column name
This commit is contained in:
committed by
Steve Chávez
parent
8f49f731d0
commit
e1cab584a3
@@ -245,7 +245,7 @@ requestToQuery schema isParent (DbRead (Node (Select colSelects tbls logicForest
|
||||
getQueryParts (Node n@(_, (name, Just Relation{relType=Child,relTable=Table{tableName=table}}, alias, _)) forst) (j,s) = (j,sel:s)
|
||||
where
|
||||
sel = "COALESCE(("
|
||||
<> "SELECT array_to_json(array_agg(row_to_json("<>pgFmtIdent table<>".*))) "
|
||||
<> "SELECT array_to_json(array_agg(row_to_json(" <> pgFmtIdent table <> ".*))) "
|
||||
<> "FROM (" <> subquery <> ") " <> pgFmtIdent table
|
||||
<> "), '[]') AS " <> pgFmtIdent (fromMaybe name alias)
|
||||
where subquery = requestToQuery schema False (DbRead (Node n forst))
|
||||
@@ -262,7 +262,7 @@ requestToQuery schema isParent (DbRead (Node (Select colSelects tbls logicForest
|
||||
getQueryParts (Node n@(_, (name, Just Relation{relType=Many,relTable=Table{tableName=table}}, alias, _)) forst) (j,s) = (j,sel:s)
|
||||
where
|
||||
sel = "COALESCE (("
|
||||
<> "SELECT array_to_json(array_agg(row_to_json("<>pgFmtIdent table<>".*))) "
|
||||
<> "SELECT array_to_json(array_agg(row_to_json(" <> pgFmtIdent table <> ".*))) "
|
||||
<> "FROM (" <> subquery <> ") " <> pgFmtIdent table
|
||||
<> "), '[]') AS " <> pgFmtIdent (fromMaybe name alias)
|
||||
where subquery = requestToQuery schema False (DbRead (Node n forst))
|
||||
|
||||
@@ -768,3 +768,13 @@ spec = do
|
||||
it "works with brackets" $
|
||||
get "/entities?id=eq.2&select=id,child_entities{id}" `shouldRespondWith`
|
||||
[json| [{"id": 2, "child_entities": [{"id": 3}]}] |] { matchHeaders = [matchContentTypeJson] }
|
||||
|
||||
context "Embedding when column name = table name" $ do
|
||||
it "works with child embeds" $
|
||||
get "/being?select=*,descendant(*)&limit=1" `shouldRespondWith`
|
||||
[json|[{"being":1,"descendant":[{"descendant":1,"being":1},{"descendant":2,"being":1},{"descendant":3,"being":1}]}]|]
|
||||
{ matchHeaders = [matchContentTypeJson] }
|
||||
it "works with many to many embeds" $
|
||||
get "/being?select=*,part(*)&limit=1" `shouldRespondWith`
|
||||
[json|[{"being":1,"part":[{"part":1}]}]|]
|
||||
{ matchHeaders = [matchContentTypeJson] }
|
||||
|
||||
Vendored
+11
@@ -323,6 +323,17 @@ INSERT INTO ranges VALUES (2, '[3,6]');
|
||||
INSERT INTO ranges VALUES (3, '[6,9]');
|
||||
INSERT INTO ranges VALUES (4, '[9,12]');
|
||||
|
||||
TRUNCATE TABLE being CASCADE;
|
||||
INSERT INTO being VALUES (1), (2), (3), (4);
|
||||
|
||||
TRUNCATE TABLE descendant CASCADE;
|
||||
INSERT INTO descendant VALUES (1,1), (2,1), (3,1), (4,2);
|
||||
|
||||
TRUNCATE TABLE part CASCADE;
|
||||
INSERT INTO part VALUES (1), (2), (3), (4);
|
||||
|
||||
TRUNCATE TABLE being_part CASCADE;
|
||||
INSERT INTO being_part VALUES (1,1), (2,1), (3,2), (4,3);
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
Vendored
+4
@@ -57,6 +57,10 @@ GRANT ALL ON TABLE
|
||||
, child_entities
|
||||
, grandchild_entities
|
||||
, ranges
|
||||
, being
|
||||
, descendant
|
||||
, being_part
|
||||
, part
|
||||
TO postgrest_test_anonymous;
|
||||
|
||||
GRANT INSERT ON TABLE insertonly TO postgrest_test_anonymous;
|
||||
|
||||
Vendored
+18
@@ -1254,6 +1254,24 @@ $$ language sql;
|
||||
create function test.get_tsearch() returns setof test.tsearch AS $$
|
||||
SELECT * FROM test.tsearch;
|
||||
$$ language sql;
|
||||
|
||||
create table test.being (
|
||||
being int primary key not null
|
||||
);
|
||||
|
||||
create table test.descendant (
|
||||
descendant int primary key not null,
|
||||
being int references test.being(being)
|
||||
);
|
||||
|
||||
create table test.part (
|
||||
part int primary key not null
|
||||
);
|
||||
|
||||
create table test.being_part (
|
||||
being int not null references test.being(being),
|
||||
part int not null references test.part(part)
|
||||
);
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
Reference in New Issue
Block a user