refactor: self relationship
* Add test for self relationship in view
This commit is contained in:
committed by
Steve Chavez
parent
c60380b5fc
commit
2be63b36d6
@@ -362,6 +362,21 @@ spec =
|
||||
}
|
||||
}]|] { matchHeaders = [matchContentTypeJson] }
|
||||
|
||||
it "embeds parent and then embeds children on a view" $
|
||||
get "/job?select=id,parent_id(*),children:job!parent_id(id,parent_id)" `shouldRespondWith`
|
||||
[json|[
|
||||
{
|
||||
"id": 1,
|
||||
"parent_id": null,
|
||||
"children": [ { "id": 2, "parent_id": 1 } ]
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"parent_id": { "id": 1, "parent_id": null },
|
||||
"children": []
|
||||
}
|
||||
]|] { matchHeaders = [matchContentTypeJson] }
|
||||
|
||||
context "two self reference foreign keys" $ do
|
||||
it "embeds parents" $
|
||||
get "/organizations?select=id,name,referee(id,name),auditor(id,name)&id=eq.3" `shouldRespondWith`
|
||||
|
||||
Vendored
+4
@@ -771,3 +771,7 @@ INSERT INTO test.xmltest VALUES
|
||||
|
||||
TRUNCATE TABLE test.oid_test CASCADE;
|
||||
INSERT INTO oid_test(id, oid_col, oid_array_col) VALUES (1, '12345', '{1,2,3,4,5}'::oid[]);
|
||||
|
||||
TRUNCATE TABLE private.internal_job CASCADE;
|
||||
INSERT INTO private.internal_job (id, parent_id) VALUES (1, null);
|
||||
INSERT INTO private.internal_job (id, parent_id) VALUES (2, 1);
|
||||
|
||||
Vendored
+1
@@ -180,6 +180,7 @@ GRANT ALL ON TABLE
|
||||
, limited_update_items_cpk_view
|
||||
, xmltest
|
||||
, oid_test
|
||||
, job
|
||||
TO postgrest_test_anonymous;
|
||||
|
||||
GRANT INSERT ON TABLE insertonly TO postgrest_test_anonymous;
|
||||
|
||||
Vendored
+12
@@ -2593,3 +2593,15 @@ CREATE TABLE oid_test(
|
||||
id int,
|
||||
oid_col oid,
|
||||
oid_array_col oid[]);
|
||||
|
||||
CREATE TABLE private.internal_job
|
||||
(
|
||||
id integer NOT NULL,
|
||||
parent_id integer,
|
||||
CONSTRAINT internal_job_pkey PRIMARY KEY (id),
|
||||
CONSTRAINT parent_fk FOREIGN KEY (parent_id) REFERENCES private.internal_job (id)
|
||||
);
|
||||
|
||||
CREATE VIEW test.job AS
|
||||
SELECT j.id, j.parent_id
|
||||
FROM private.internal_job j;
|
||||
|
||||
Reference in New Issue
Block a user