Postgrest: Embed resource from another schema table

Created on 24 Feb 2019  路  4Comments  路  Source: PostgREST/postgrest

Environment

Description of issue

Perhaps this is more a feature request than a bug.
I've noticed that Postgrest gives a 'No relationship found error' if a foreign key references a table from another schema.
Is Postgrest any close to support this feature? I am aware that it would imply to load the schema of the referenced table and so on. Still, maybe if the embedding url specified the embedded columns this would be an easy addition.

Thanks.

Most helpful comment

This already works. Create a view of the table in the unexposed schema in your api schema. Example:

create table private.people(
  id int primary key,
  name text
);
insert into private.people values(1, 'Pedro');

create table api.details(
  id int,
  phone text,
  person_id int references private.people(id)
);
insert into api.details values(1, '888-8888', 1);

create view api.people as
select id, name from private.people;

curl  "http://localhost:3000/details?select=id,phone,person:people(id,name)"
[{"id":1,"phone":"888-8888","person":{"id":1,"name":"Pedro"}}]

All 4 comments

This already works. Create a view of the table in the unexposed schema in your api schema. Example:

create table private.people(
  id int primary key,
  name text
);
insert into private.people values(1, 'Pedro');

create table api.details(
  id int,
  phone text,
  person_id int references private.people(id)
);
insert into api.details values(1, '888-8888', 1);

create view api.people as
select id, name from private.people;

curl  "http://localhost:3000/details?select=id,phone,person:people(id,name)"
[{"id":1,"phone":"888-8888","person":{"id":1,"name":"Pedro"}}]

What does the "person" accomplish in this example curl command "person:people"? Is a colon and period interchangable in this situation?

@BrandonChubb In that case person is just an alias. Not interchangeable with a period since that's used for the feature introduced in https://github.com/PostgREST/postgrest/pull/918

Was this page helpful?
0 / 5 - 0 ratings

Related issues

waghanza picture waghanza  路  28Comments

dudleycarr picture dudleycarr  路  25Comments

nicklasaven picture nicklasaven  路  79Comments

ruslantalpa picture ruslantalpa  路  25Comments

steve-chavez picture steve-chavez  路  26Comments