【发布时间】:2009-04-17 04:20:21
【问题描述】:
我正在为 mysql 设计一个 bd 方案。我的数据库存储 3 种点:a、b 或 c,路径由 n 对点组成:
路线 = [ (a1 or b1 or c1 ; a2 or b2 or c2), (a2 or b2 or c2 ; a3 or b3 or c3), ...]
create table a_points (
point_id serial not null,
owner_id bigint unsigned not null,
name varchar(20) not null,
primary key (point_id),
foreign key (owner_id) references othertable (other_id)
) engine = InnoDB;
create table b_points (
point_id serial not null,
owner_id bigint unsigned not null,
name varchar(20) not null,
fields varchar(20) not null,
primary key (point_id),
foreign key (owner_id) references othertable (owner_id)
) engine = InnoDB;
create table c_points (
point_id serial not null,
name varchar(20) not null,
cfields varchar(20) not null,
primary key (point_id)
) engine = InnoDB;
create table paths (
path_id serial not null,
name varchar(20) not null,
primary key (path_id)
) engine = InnoDB;
create table point_pairs (
pair_id serial not null,
path_id bigint unsigned not null,
point_from bigint unsigned not null,
point_to bigint unsigned not null,
table_from varchar(9) not null,
table_to varchar(9) not null,
primary key (pair_id),
foreign key (path_id) references paths (path_id)
) engine = InnoDB;
(*) 一对点是(m, n) 或者从m到n
所以我将一对点连同它们的路径 ID 一起存储。我的问题是我必须创建两列来标识表的名称 m 和 n。 m 的 table_from 和 n 的 table_to。因此,我必须在我的代码中使用这两列来了解路线中保存了哪些类型的点(路径和 point_pairs 表)。我的问题:MySql 是否提供了一些东西来引用同一列中的 n 个外键?我已经考虑过加入 a、b 和 c 点表,但我必须在这个新表中添加一个类型列,我的 php 类将变得无用。
提前致谢!
【问题讨论】:
标签: mysql database-design polymorphic-associations