feat: add one to one relationship for embedding
BREAKING CHANGE: For the cases where one to one relationships are detected, json objects will be returned instead of json arrays of length 1. If you wish to override this behavior, you can use computed relationships to return arrays again.
This commit is contained in:
committed by
Steve Chavez
parent
2afe13fa89
commit
c45e85c5a6
Vendored
+12
@@ -812,3 +812,15 @@ INSERT INTO designers(id, name) VALUES (1, 'Sid Meier'), (2, 'Hironobu Sakaguchi
|
||||
|
||||
TRUNCATE TABLE videogames CASCADE;
|
||||
INSERT INTO videogames(id, name, designer_id) VALUES (1, 'Civilization I', 1), (2, 'Civilization II', 1), (3, 'Final Fantasy I', 2), (4, 'Final Fantasy II', 2);
|
||||
|
||||
TRUNCATE TABLE students CASCADE;
|
||||
INSERT INTO students(id, code, name) VALUES (1, '0001', 'John Doe'), (2, '0002', 'Jane Doe');
|
||||
|
||||
TRUNCATE TABLE students_info CASCADE;
|
||||
INSERT INTO students_info(id, code, address) VALUES (1, '0001', 'Street 1'), (2, '0002', 'Street 2');
|
||||
|
||||
TRUNCATE TABLE country CASCADE;
|
||||
INSERT INTO country(id, name) VALUES (1, 'Afghanistan'), (2, 'Algeria');
|
||||
|
||||
TRUNCATE TABLE capital CASCADE;
|
||||
INSERT INTO capital(id, name, country_id) VALUES (1, 'Kabul', 1), (2, 'Algiers', 2);
|
||||
|
||||
Vendored
+10
@@ -199,6 +199,16 @@ GRANT ALL ON TABLE
|
||||
, unsafe_delete_items
|
||||
, videogames
|
||||
, designers
|
||||
, students
|
||||
, students_info
|
||||
, students_view
|
||||
, students_info_view
|
||||
, country
|
||||
, capital
|
||||
, first
|
||||
, second
|
||||
, first_1
|
||||
, second_1
|
||||
TO postgrest_test_anonymous;
|
||||
|
||||
GRANT INSERT ON TABLE insertonly TO postgrest_test_anonymous;
|
||||
|
||||
Vendored
+74
-1
@@ -2400,7 +2400,7 @@ CREATE TABLE contact (
|
||||
|
||||
CREATE TABLE clientinfo (
|
||||
id serial primary key
|
||||
, clientid int unique references client(id)
|
||||
, clientid int references client(id)
|
||||
, other text
|
||||
);
|
||||
|
||||
@@ -2753,3 +2753,76 @@ $$ LANGUAGE sql STABLE ROWS 1;
|
||||
CREATE FUNCTION test.videogames(test.designers) RETURNS SETOF test.videogames AS $$
|
||||
SELECT * FROM test.videogames WHERE FALSE;
|
||||
$$ LANGUAGE sql STABLE;
|
||||
|
||||
CREATE TABLE test.students(
|
||||
id int
|
||||
, code text
|
||||
, name text
|
||||
, primary key(id, code)
|
||||
);
|
||||
|
||||
CREATE TABLE test.students_info(
|
||||
id int
|
||||
, code text
|
||||
, address text
|
||||
, primary key(id, code)
|
||||
, foreign key (id, code) references test.students(id, code) on delete cascade
|
||||
);
|
||||
|
||||
CREATE TABLE test.country(
|
||||
id int primary key
|
||||
, name text
|
||||
);
|
||||
|
||||
CREATE TABLE test.capital(
|
||||
id int primary key
|
||||
, name text
|
||||
, country_id int unique
|
||||
, foreign key (country_id) references test.country(id)
|
||||
);
|
||||
|
||||
CREATE FUNCTION test.allcountries() RETURNS SETOF test.country AS $$
|
||||
SELECT * FROM test.country;
|
||||
$$ LANGUAGE sql STABLE;
|
||||
|
||||
CREATE FUNCTION test.allcapitals() RETURNS SETOF test.capital AS $$
|
||||
SELECT * FROM test.capital;
|
||||
$$ LANGUAGE sql STABLE;
|
||||
|
||||
create view students_view as
|
||||
select * from students;
|
||||
|
||||
create view students_info_view as
|
||||
select * from students_info;
|
||||
|
||||
create table test.second (
|
||||
id int primary key,
|
||||
name text
|
||||
);
|
||||
|
||||
create table test.first (
|
||||
id int primary key,
|
||||
name text,
|
||||
second_id_1 int references test.second unique,
|
||||
second_id_2 int references test.second unique
|
||||
);
|
||||
|
||||
create table test.second_1 (
|
||||
id int primary key,
|
||||
name text
|
||||
);
|
||||
|
||||
create table test.first_1 (
|
||||
id int primary key,
|
||||
name text,
|
||||
second_id_1 int references test.second unique,
|
||||
second_id_2 int references test.second unique
|
||||
);
|
||||
|
||||
CREATE FUNCTION test.second_1(test.first_1) RETURNS SETOF test.second_1 AS $$
|
||||
SELECT * FROM test.second_1 WHERE id = $1.second_id_1;
|
||||
$$ LANGUAGE sql STABLE ROWS 1;
|
||||
|
||||
CREATE FUNCTION test.first_1(test.second_1) RETURNS SETOF test.first_1 AS $$
|
||||
SELECT * FROM test.first_1 WHERE second_id_1 = $1.id;
|
||||
$$ LANGUAGE sql STABLE ROWS 1;
|
||||
|
||||
Reference in New Issue
Block a user