Fix Parent Relation when having many views(#1044)
This commit is contained in:
committed by
Steve Chávez
parent
ff709a65e5
commit
349a5ae076
@@ -398,6 +398,19 @@ spec = do
|
||||
[json|[{"t_id":1,"name":"Windows 7","clients":{"id":1,"name":"Microsoft"},"tasks":[{"id":1,"name":"Design w7"},{"id":2,"name":"Code w7"}]}]|]
|
||||
{ matchHeaders = [matchContentTypeJson] }
|
||||
|
||||
it "detects parent relations when having many views of a private table" $ do
|
||||
get "/books?select=title,author(name)&id=eq.5" `shouldRespondWith`
|
||||
[json|[ { "title": "Farenheit 451", "author": { "name": "Ray Bradbury" } } ]|]
|
||||
{ matchHeaders = [matchContentTypeJson] }
|
||||
get "/forties_books?select=title,author(name)&limit=1" `shouldRespondWith`
|
||||
[json|[ { "title": "1984", "author": { "name": "George Orwell" } } ]|]
|
||||
{ matchHeaders = [matchContentTypeJson] }
|
||||
get "/fifties_books?select=title,author(name)&limit=1" `shouldRespondWith`
|
||||
[json|[ { "title": "The Catcher in the Rye", "author": { "name": "J.D. Salinger" } } ]|]
|
||||
{ matchHeaders = [matchContentTypeJson] }
|
||||
get "/sixties_books?select=title,author(name)&limit=1" `shouldRespondWith`
|
||||
[json|[ { "title": "To Kill a Mockingbird", "author": { "name": "Harper Lee" } } ]|]
|
||||
{ matchHeaders = [matchContentTypeJson] }
|
||||
|
||||
it "requesting children with composite key" $
|
||||
get "/users_tasks?user_id=eq.2&task_id=eq.6&select=*, comments{content}" `shouldRespondWith`
|
||||
|
||||
Vendored
+24
@@ -359,3 +359,27 @@ INSERT INTO organizations VALUES (1, 'Referee Org', null, null);
|
||||
INSERT INTO organizations VALUES (2, 'Auditor Org', null, null);
|
||||
INSERT INTO organizations VALUES (3, 'Acme', 1, 2);
|
||||
INSERT INTO organizations VALUES (4, 'Umbrella', 1, 2);
|
||||
|
||||
SET search_path = private, pg_catalog;
|
||||
|
||||
TRUNCATE TABLE authors CASCADE;
|
||||
INSERT INTO authors VALUES (1, 'George Orwell');
|
||||
INSERT INTO authors VALUES (2, 'Anne Frank');
|
||||
INSERT INTO authors VALUES (3, 'Antoine de Saint-Exupéry');
|
||||
INSERT INTO authors VALUES (4, 'J.D. Salinger');
|
||||
INSERT INTO authors VALUES (5, 'Ray Bradbury');
|
||||
INSERT INTO authors VALUES (6, 'William Golding');
|
||||
INSERT INTO authors VALUES (7, 'Harper Lee');
|
||||
INSERT INTO authors VALUES (8, 'Kurt Vonnegut');
|
||||
INSERT INTO authors VALUES (9, 'Ken Kesey');
|
||||
|
||||
TRUNCATE TABLE books CASCADE;
|
||||
INSERT INTO books VALUES (1, '1984', 1949, 1);
|
||||
INSERT INTO books VALUES (2, 'The Diary of a Young Girl', 1947, 2);
|
||||
INSERT INTO books VALUES (3, 'The Little Prince', 1947, 3);
|
||||
INSERT INTO books VALUES (4, 'The Catcher in the Rye', 1951, 4);
|
||||
INSERT INTO books VALUES (5, 'Farenheit 451', 1953, 5);
|
||||
INSERT INTO books VALUES (6, 'Lord of the Flies', 1954, 6);
|
||||
INSERT INTO books VALUES (7, 'To Kill a Mockingbird', 1960, 7);
|
||||
INSERT INTO books VALUES (8, 'Slaughterhouse-Five', 1969, 8);
|
||||
INSERT INTO books VALUES (9, 'One Flew Over the Cuckoo''s Nest', 1962, 9);
|
||||
|
||||
Vendored
+5
@@ -68,6 +68,11 @@ GRANT ALL ON TABLE
|
||||
, only_pk
|
||||
, family_tree
|
||||
, organizations
|
||||
, authors
|
||||
, books
|
||||
, forties_books
|
||||
, fifties_books
|
||||
, sixties_books
|
||||
TO postgrest_test_anonymous;
|
||||
|
||||
GRANT INSERT ON TABLE insertonly TO postgrest_test_anonymous;
|
||||
|
||||
Vendored
+19
@@ -1390,3 +1390,22 @@ create table test.organizations (
|
||||
);
|
||||
alter table only test.organizations add constraint pptr1 foreign key (referee) references test.organizations(id);
|
||||
alter table only test.organizations add constraint pptr2 foreign key (auditor) references test.organizations(id);
|
||||
|
||||
create table private.authors(
|
||||
id integer primary key,
|
||||
name text
|
||||
);
|
||||
|
||||
create table private.books(
|
||||
id integer primary key,
|
||||
title text,
|
||||
publication_year smallint,
|
||||
author_id integer references private.authors(id)
|
||||
);
|
||||
|
||||
create view test.authors as select id, name from private.authors;
|
||||
|
||||
create view test.books as select id, title, publication_year, author_id from private.books;
|
||||
create view test.forties_books as select id, title, publication_year, author_id from private.books where publication_year >= 1940 and publication_year < 1950;
|
||||
create view test.fifties_books as select id, title, publication_year, author_id from private.books where publication_year >= 1950 and publication_year < 1960;
|
||||
create view test.sixties_books as select id, title, publication_year, author_id from private.books where publication_year >= 1960 and publication_year < 1970;
|
||||
|
||||
Reference in New Issue
Block a user