Flutter Supabase - 连接表
我有 2 个表
- 部门(id,department_name)
- 程序(id,program_name,department_id)
Department 表中的外键
Programs 中的 dept_id 是我想要加入的 Program 表中的 department_id 和 Department 表中的 id
我无法在 Flutter supabase supabase_flutter: ^0.2.12
中执行此操作。请帮帮我
谢谢
编辑: 我想从前端执行此操作。 (扑)
CREATE TABLE Departments (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL
);
CREATE TABLE Programs (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
dept_id INTEGER,
FOREIGN KEY (dept_id) references Departments(id)
);
INSERT INTO Departments VALUES (1, 'DEPT_A');
INSERT INTO Departments VALUES (2, 'DEPT_B');
INSERT INTO Programs VALUES (1, 'PROG_A', 1);
INSERT INTO Programs VALUES (2, 'PROG_B', 1);
INSERT INTO Programs VALUES (3, 'PROG_C', 2);
INSERT INTO Programs VALUES (4, 'PROG_D', 2);
SELECT Departments.name, Departments.id, Programs.name, Programs.id
FROM Departments
INNER JOIN Programs
ON Departments.id = Programs.dept_id;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您的数据库有关系,您也可以查询相关表。
这直接来自文档:Supabase Dart 文档
If your database has relationships, you can query related tables too.
This is directly from the docs: Supabase Dart Docs
例如,您有两个表“用户”和“衣服”。
并且您在“用户”列“clothe_id”中作为“衣服”中“id”列的外键。
您可以使用此代码来获取表格。
您还可以按“衣服”中的“级别”列进行过滤:
For example, you have two tables "users" and "clothes".
And you have in "users" column "clothe_id" as forieng key for column "id" in "clothes".
You can use this code to get tables.
Also you can filter, for example, by column "level" in "clothes":
您可以通过在要添加一个列上的列上的编辑来从表编辑器内部设置supabase中的外键关系。
you can set up a foreign key relation in supabase from within your table editor by pressing edit on the column you want to add one to.