fix: inaccurate result count when an inner embed is selected after a normal embed in the query string
This commit is contained in:
@@ -200,7 +200,7 @@ spec =
|
||||
|
||||
it "works with views" $ do
|
||||
get "/authors?select=*,books!inner(*)&books.title=eq.1984" `shouldRespondWith`
|
||||
[json| [{"id":1,"name":"George Orwell","books":[{"id":1,"title":"1984","publication_year":1949,"author_id":1}]}] |]
|
||||
[json| [{"id":1,"name":"George Orwell","books":[{"id":1,"title":"1984","publication_year":1949,"author_id":1,"first_publisher_id":1}]}] |]
|
||||
{ matchHeaders = [matchContentTypeJson] }
|
||||
request methodHead "/authors?select=*,books!inner(*)&books.title=eq.1984" [("Prefer", "count=exact")] mempty
|
||||
`shouldRespondWith` ""
|
||||
@@ -354,3 +354,25 @@ spec =
|
||||
, matchHeaders = [ matchContentTypeJson
|
||||
, "Content-Range" <:> "0-2/3" ]
|
||||
}
|
||||
|
||||
it "works alongside another embedding" $ do
|
||||
-- https://github.com/PostgREST/postgrest/issues/2342
|
||||
get "/books?select=id,authors(name),publishers!inner(name)&id=gte.7"
|
||||
`shouldRespondWith`
|
||||
[json| [
|
||||
{"id":7,"authors":{"name":"Harper Lee"},"publishers":{"name":"J. B. Lippincott & Co."}},
|
||||
{"id":8,"authors":{"name":"Kurt Vonnegut"},"publishers":{"name":"Delacorte"}},
|
||||
{"id":9,"authors":{"name":"Ken Kesey"},"publishers":{"name":"Viking Press & Signet Books"}}] |]
|
||||
{ matchHeaders = [matchContentTypeJson] }
|
||||
request methodHead "/books?select=id,authors(name),publishers!inner(name)&id=gte.7" [("Prefer", "count=exact")] mempty
|
||||
`shouldRespondWith` ""
|
||||
{ matchStatus = 200
|
||||
, matchHeaders = [ matchContentTypeJson
|
||||
, "Content-Range" <:> "0-2/3" ]
|
||||
}
|
||||
request methodHead "/books?select=id,publishers!inner(name),authors(name)&id=gte.7" [("Prefer", "count=exact")] mempty
|
||||
`shouldRespondWith` ""
|
||||
{ matchStatus = 200
|
||||
, matchHeaders = [ matchContentTypeJson
|
||||
, "Content-Range" <:> "0-2/3" ]
|
||||
}
|
||||
|
||||
Vendored
+2
@@ -445,6 +445,7 @@ 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');
|
||||
INSERT INTO authors VALUES (10, 'Fyodor Dostoevsky');
|
||||
|
||||
TRUNCATE TABLE publishers CASCADE;
|
||||
INSERT INTO publishers VALUES (1, 'Secker & Warburg');
|
||||
@@ -467,6 +468,7 @@ INSERT INTO books VALUES (6, 'Lord of the Flies', 1954, 6, 6);
|
||||
INSERT INTO books VALUES (7, 'To Kill a Mockingbird', 1960, 7, 7);
|
||||
INSERT INTO books VALUES (8, 'Slaughterhouse-Five', 1969, 8, 8);
|
||||
INSERT INTO books VALUES (9, 'One Flew Over the Cuckoo''s Nest', 1962, 9, 9);
|
||||
INSERT INTO books VALUES (10, 'Crime and Punishment', 1866, 10, null);
|
||||
|
||||
SET search_path = test, pg_catalog;
|
||||
|
||||
|
||||
Vendored
+1
@@ -89,6 +89,7 @@ GRANT ALL ON TABLE
|
||||
, managers
|
||||
, organizations
|
||||
, authors
|
||||
, publishers
|
||||
, books
|
||||
, forties_books
|
||||
, fifties_books
|
||||
|
||||
Vendored
+2
-1
@@ -1461,8 +1461,9 @@ create table private.books(
|
||||
);
|
||||
|
||||
create view test.authors as select id, name from private.authors;
|
||||
create view test.publishers as select id, name from private.publishers;
|
||||
|
||||
create view test.books as select id, title, publication_year, author_id from private.books;
|
||||
create view test.books as select id, title, publication_year, author_id, first_publisher_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