目前我有一个看起来像这样的模式:
create table person(
id uuid primary key default gen_random_uuid() not null,
);
create table car(
id uuid primary key default gen_random_uuid() not null,
);
create table extra(
id uuid primary key default gen_random_uuid() not null,
);
create table car_extra_m2m(
car_id uuid not null references car(id) on delete cascade,
extra_id uuid not null references extra(id) on delete cascade,
primary key (car_id, extra_id)
);
create table person_extra_m2m(
person_id uuid not null references person(id) on delete cascade,
extra_id uuid not null references extra(id) on delete cascade,
primary key (person_id, extra_id)
);
是否可以在一个多对多表中表示两个多对多表?由于我们使用的是 uuid,所以 id 永远不会发生冲突,所以有可能仅从 uuid 知道类型?
像这个伪代码:(编辑:postgresql 中的语法无效,是否存在有效的语法?)
create table extra_m2m(
person_or_car_id uuid not null references (person(id) or car(id)) on delete cascade,
extra_id uuid not null references extra(id) on delete cascade,
primary key (person_or_car_id, extra_id)
);