Fab*_*bio 1 dart flutter supabase supabase-database
假设我有 3 张表:
我想要做的是将 Table1 和 Table2 连接起来,然后选择具有特定列值的行(例如 col4 == "123")
我尝试过的:
supabase.from("Table3").select(
'''
Table1 (
col1,
col2
),
Table2 (
col3,
col4
),
'''
).eq("Table2.col4", "123").execute();
Run Code Online (Sandbox Code Playgroud)
这样做的问题是,对于与查询匹配的行,它返回具有 Table1 和 Table2 属性的正确对象,但对于与查询不匹配的行(因此不应返回),它返回具有 Table1 属性和 Table2 的对象属性设置为 null。
上述查询的示例:
表 1 |id | 第 1 列 | 列2| |---|------|-----| |1 | 值1 | 值2| |2 | 值3 | 值4|
表2 |id | 第 3 栏 | 第 4 栏 | |---|------|------| |3 | 值5 | 123 | 123 |4 | 瓦尔7 | val8 |
表 3 |table1_id| 表2_id| |---------|----------| |1 | 3 | |2 | 4 |
结果 |col1 | 列2 | 第 3 栏 | 第 4 栏 | |-----|------|------|------| |值1 | 值2 | 值5 | 123 | 123 |值3 | 值4 | 空 | 空 |
如何防止它返回与查询不匹配的行?
您可以!inner为此使用关键字。!inner允许您通过将过滤器应用于合适的结果来过滤根表结果。
supabase.from("Table3").select(
'''
Table1!inner (
col1,
col2
),
Table2!inner (
col3,
col4
),
'''
).eq("Table2.col4", "123").execute();
Run Code Online (Sandbox Code Playgroud)