0

我的用户表结构及其地址详细信息如下

CREATE TABLE tbl_users (
  id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  loginname varchar(128) NOT NULL,
  enabled enum("True","False"),
  approved enum("True","False"),
  password varchar(128) NOT NULL,
  email varchar(128) NOT NULL,
  role_id int(20) NOT NULL DEFAULT '2',
  name varchar(70) NOT NULL,
  co_type enum("S/O","D/O","W/O") DEFAULT "S/O",
  co_name varchar(70),
  gender enum("MALE","FEMALE","OTHER") DEFAULT "MALE",
  dob date DEFAULT NULL,
  maritalstatus enum("SINGLE","MARRIED","DIVORCED","WIDOWER") DEFAULT "MARRIED",
  occupation varchar(100) DEFAULT NULL,
  occupationtype_id int(20) DEFAULT NULL,
  occupationindustry_id int(20) DEFAULT NULL,
  contact_id bigint(20) unsigned DEFAULT NULL,
  signupreason varchar(500),
  PRIMARY KEY (id),
  UNIQUE KEY loginname (loginname),
  UNIQUE KEY email (email),
  FOREIGN KEY (role_id) REFERENCES tbl_roles (id),
  FOREIGN KEY (occupationtype_id) REFERENCES tbl_occupationtypes (id),
  FOREIGN KEY (occupationindustry_id) REFERENCES tbl_occupationindustries (id),
  FOREIGN KEY (contact_id) REFERENCES tbl_contacts (id)
) ENGINE=InnoDB;

CREATE TABLE tbl_contacts (
  id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  contact_type enum("cres","pres","coff"),
  address varchar(300) DEFAULT NULL,
  landmark varchar(100) DEFAULT NULL,
  district_id int(11) DEFAULT NULL,
  city_id int(20) DEFAULT NULL,
  state_id int(20) DEFAULT NULL,
  pin_id bigint(20) unsigned DEFAULT NULL,
  area_id bigint(20) unsigned DEFAULT NULL,
  po_id bigint(20) unsigned DEFAULT NULL,
  phone1 varchar(20) DEFAULT NULL,
  phone2 varchar(20) DEFAULT NULL,
  mobile1 varchar(20) DEFAULT NULL,
  mobile2 varchar(20) DEFAULT NULL,
  PRIMARY KEY (id),
  FOREIGN KEY (district_id) REFERENCES tbl_districts (id),
  FOREIGN KEY (city_id) REFERENCES tbl_cities (id),
  FOREIGN KEY (state_id) REFERENCES tbl_states (id)
) ENGINE=InnoDB;

CREATE TABLE tbl_states (
  id int(20) NOT NULL AUTO_INCREMENT,
  name varchar(70) DEFAULT NULL,
  PRIMARY KEY (id)
) ENGINE=InnoDB;


CREATE TABLE tbl_districts (
  id int(20) NOT NULL AUTO_INCREMENT,
  name varchar(70) DEFAULT NULL,
  state_id int(20) DEFAULT NULL,
  PRIMARY KEY (id),
  FOREIGN KEY (state_id) REFERENCES tbl_states (id)
) ENGINE=InnoDB;


CREATE TABLE tbl_cities (
  id int(20) NOT NULL AUTO_INCREMENT,
  name varchar(70) DEFAULT NULL,
  district_id int(20) DEFAULT NULL,
  state_id int(20) DEFAULT NULL,
  PRIMARY KEY (id),
  FOREIGN KEY (district_id) REFERENCES tbl_districts (id),
  FOREIGN KEY (state_id) REFERENCES tbl_states (id)
) ENGINE=InnoDB;

关系如下 用户有多个联系人,即永久地址、当前地址、办公地址。每个联系人都有州和城市。

用户->联系人->这样的状态

如何一次性保存这种结构的模型。

请尽快回复

4

2 回答 2

0

I believe I had a similar issue saving a multi leveled model with many foreign keys. It doesn't seem that it can easily be saved in 'one go'... Take a look at my solution here

于 2010-06-25T23:00:54.043 回答
0

您可能会在 google 代码上查看 gii-templates 扩展 -

谷歌代码上的 gii 模板

->> 它可能会更好地记录下来,但它会尝试做你需要的事情。(如果你能很好地实现它可能会节省一些时间,但如果我是你,我什至会考虑手动编码。)

于 2010-08-16T19:42:29.880 回答