Given the following schema:
CREATE TABLE organization (
org_name text NOT NULL,
PRIMARY KEY (org_name)
);
CREATE TABLE teams (
org_name text NOT NULL,
team_name text NOT NULL,
PRIMARY KEY (org_name, team_name),
FOREIGN KEY (org_name)
REFERENCES organization (org_name)
);
CREATE TABLE projects (
org_name text NOT NULL,
team_name text NOT NULL,
project_name text NOT NULL,
products jsonb,
PRIMARY KEY (org_name, team_name, project_name),
FOREIGN KEY (org_name)
REFERENCES organization (org_name),
FOREIGN KEY (org_name, team_name)
REFERENCES teams (org_name, team_name)
);
I want to query the teams table but also return the products from the projects table. Is there a way to do this?
For single relationships set, then you can do the following (assuming a top-bottom relationship as:
organization -> teamsandteams -> projectsIn this case, it would not be possible and you would get the following error:
In this case, you can pick the relationship when calling supabase with either:
teams!projectsorteams!teams_org_name_fkey. The former is preferred for most cases.Output: