我有以下结构
create table organisation (
id uuid primary key,
organisation_name varchar not null
);
create table organisation_member (
id uuid primary key,
email varchar not null,
name varchar not null,
organisation uuid not null,
uid uuid,
foreign key (organisation) references organisation(id),
foreign key (uid) references users(id)
);
create table organisation_member_invite (
id uuid primary key,
organisation_member uuid not null,
uid uuid not null,
foreign key (organisation_member) references organisation_member(id),
foreign key (uid) references users(id)
)
使用带有 supabase 的 Postgrest,我想查询所有organisations
链接到organisation_member_invite
. 在 SQL 中,我只会做一个简单的左连接
select *, o.* from organisation_member_invite as omi
right join organisation_member as om on om.id = omi.organisation_member
left join organisation as o on o.id = om.organisation
where omi.user = <user_id>
使用 postgrest,这变成了类似的东西
...from('organisation_member_invite').select('''
*,
organisation_member(
organisation(*)
)
''').eq('user', uid);
不幸的是,在打印错误变量的几个部分时,我得到以下输出。
打印(错误提示)
Try changing 'organisation' to one of the following: 'organisation!organisation_member_organisation_fkey', 'organisation!organisation_function', 'organisation!organisation_member_invitation'. Find the desired relationship in the 'details' key.
打印(错误。详细信息)
details: [
{relationship: organisation_member_organisation_fkey[organisation][id], embedding: organisation_member with organisation, cardinality: many-to-one},
{relationship: public.organisation_function[organisation_function_member_fkey][organisation_function_organisation_fkey], embedding: organisation_member with organisation, cardinality: many-to-many},
{relationship: public.organisation_member_invitation[organisation_member_invitation_membership_fkey][organisation_member_invitation_organisation_fkey], embedding: organisation_member with organisation, cardinality: many-to-many}
]
打印(错误消息)
Could not embed because more than one relationship was found for 'organisation_member' and 'organisation'
. organisation
除了in的外键之外,我没有任何其他关系organisation_member
。我真的很喜欢这种表示法,但它也限制了我表达我真正想要的数据。
我究竟做错了什么?