Thinkphp5 联合(关联)查询

按照官方手册http://www.kancloud.cn/manual/thinkphp5/142357  折腾了很久还是无法实现,可能还是我理解的不对,最后使用了如下方式:


1. 项目表

DROP TABLE IF EXISTS `darling_project`;
CREATE TABLE `darling_project` (
  `project_id` int(32) NOT NULL AUTO_INCREMENT,
  `project_name` varchar(20) NOT NULL,
  `create_time` int(32) NOT NULL,
  PRIMARY KEY (`project_id`),
  UNIQUE KEY `project_id` (`project_id`),
  UNIQUE KEY `project_name` (`project_name`)
);

2. 版本号表
DROP TABLE IF EXISTS `darling_version`;
CREATE TABLE `darling_version` (
  `version_id` int(32) NOT NULL AUTO_INCREMENT,
  `project_id` int(32) NOT NULL,
  `version_name` varchar(128) NOT NULL,
  `create_time` int(32) NOT NULL,
  PRIMARY KEY (version_id),
  UNIQUE KEY `version_id` (`version_id`)
);


3. 联合查询

                $where=array(
                    "version_id"=>$_POST['version_id']
                );               
                $Project_version = model('Project')->join("darling_version","darling_version.project_id = darling_project.project_id")->where($where)->find();



你可能感兴趣的:(ThinkPHP)