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

多くの外部キーを持つマルチレベルモデルを保存するときにも同様の問題が発生したと思います。「ワンゴー」で簡単に保存できるようには思えません...ここで私の解決策を見てください

于 2010-06-25T23:00:54.043 に答える
0

Googleコードのgii-templates拡張機能を見ているかもしれません-

Google コードの gii テンプレート

->> より適切に文書化される可能性がありますが、必要なことを実行しようとします。(うまく実装すれば時間を節約できるかもしれませんが、私があなたならハンドコーディングすることも考えます。)

于 2010-08-16T19:42:29.880 に答える