CREATE TABLE `authordetails` (
`a1` varchar(100) NOT NULL,
`a2` varchar(100) DEFAULT NULL,
`a3` varchar(100) DEFAULT NULL,
`a4` varchar(100) DEFAULT NULL,
`a5` varchar(100) DEFAULT NULL,
`aid` int(10) NOT NULL AUTO_INCREMENT,
`docid` int(10) NOT NULL,
`user_id` int(10) NOT NULL,
PRIMARY KEY (`aid`),
KEY `FK_authordetails` (`docid`),
CONSTRAINT `FK_authordetails` FOREIGN KEY (`docid`) REFERENCES `details` (`details_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
CREATE TABLE `details` (
`articletype` varchar(10) NOT NULL,
`titleofpaper` varchar(100) DEFAULT NULL,
`abstract` varchar(100) DEFAULT NULL,
`details_id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
PRIMARY KEY (`details_id`),
KEY `FK_details` (`user_id`),
CONSTRAINT `FK_details` FOREIGN KEY (`user_id`) REFERENCES `signup` (`userid`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1
我想在authordetails表中使用detais-id作为doc_id当我打开作者detais表时,它会自动显示details_id 请帮帮我
答案 0 :(得分:1)
假设您有authorndtails表的AuthorDetails模型和详细信息模型的详细信息表,那么您需要按照以下步骤操作:
在AuthorDetails类关系方法中添加以下关系:
'details' => array(self::BELONGS_TO, 'Details', 'doc_id'),
在Details类中添加以下关系:
'author_details' => array(self::HAS_MANY, 'AuthorDetails', 'doc_id'),
现在您可以访问:
$details->author_details;