자녀 생성시 부모 레코드를 자동 생성하려고합니다.Kohana orm 상속
예.
CREATE TABLE IF NOT EXISTS `front_end_users` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`userid` int(11) unsigned NOT NULL,
`tel` varchar(20) NOT NULL,
`addr1` varchar(255) NOT NULL,
`addr2` varchar(255) NOT NULL,
`city` int(11) NOT NULL,
`zip` varchar(10) NOT NULL,
PRIMARY KEY (`id`),
KEY `fk_userid` (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`email` varchar(127) NOT NULL,
`username` varchar(32) NOT NULL DEFAULT '',
`password` char(64) NOT NULL,
`logins` int(10) unsigned NOT NULL DEFAULT '0',
`last_login` int(10) unsigned DEFAULT NULL,
`reset_token` char(64) NOT NULL DEFAULT '',
`status` varchar(20) NOT NULL DEFAULT '',
`last_failed_login` datetime NOT NULL,
`failed_login_count` int(11) NOT NULL DEFAULT '0',
`created` datetime NOT NULL,
`modified` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_username` (`username`),
UNIQUE KEY `uniq_email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
CREATE TABLE IF NOT EXISTS `promouter` (
`userid` int(10) unsigned NOT NULL,
`balance` float NOT NULL,
`commision` float NOT NULL,
`mountly_fee` float NOT NULL,
`verified` tinyint(1) NOT NULL DEFAULT '0',
KEY `promouter_ibfk_1` (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `front_end_users`
ADD CONSTRAINT `front_end_users_ibfk_1` FOREIGN KEY (`userid`) REFERENCES `users` (`id`) ON DELETE CASCADE;
ALTER TABLE `promouter`
ADD CONSTRAINT `promouter_ibfk_1` FOREIGN KEY (`userid`) REFERENCES `front_end_users` (`userid`) ON DELETE CASCADE;
users->front_end_users->promouter
내가 자동으로보다 로그인, 비밀번호, 주소 promouter
를 작성하는 경우, 내가 원하는 사용자 (login, password)
, front_end_users (addr1, addr2, userid)
및 promouter (userid)
에서 해당 필드를 삽입합니다.
그리고 여러 가지 역할이 있습니다. 그래서 사용자 모델에 have_one을 추가 할 수 없습니다. 하지만 have_one을 front_end_users 및 promouter 모델에 추가했습니다.
은 다른 테이블과 관련된 필드를 유지하는 클래스를 저장하는 것을 의미합니다. 방아쇠를 당기는 빈 테이블이 아닙니다. – Peinguin
내 대답을 편집했습니다. –