ThinkPHP3.2中关联查询
CREATE TABLE `test_avatar` (<br /> `uid` int(11) unsigned NOT NULL DEFAULT '0',<br /> `avatar` varchar(255) NOT NULL DEFAULT '',<br /> PRIMARY KEY (`uid`)<br />) ENGINE=MyISAM DEFAULT CHARSET=utf8;<br />INSERT INTO `test_avatar` VALUES (1,'./Uploads/admin.jpg');<br /><br />CREATE TABLE `test_pro` (<br /> `id` int(11) unsigned NOT NULL AUTO_INCREMENT,<br /> `uid` int(11) unsigned NOT NULL DEFAULT '0',<br /> `name` varchar(255) NOT NULL DEFAULT '',<br /> PRIMARY KEY (`id`)<br />) ENGINE=MyISAM DEFAULT CHARSET=utf8;<br />INSERT INTO `test_pro` VALUES (1,1,'产品1'),(2,1,'产品2');<br /><br />CREATE TABLE `test_user` (<br /> `id` int(11) unsigned NOT NULL AUTO_INCREMENT,<br /> `username` varchar(50) NOT NULL DEFAULT '',<br /> `tel` int(11) unsigned NOT NULL DEFAULT '0',<br /> PRIMARY KEY (`id`)<br />) ENGINE=MyISAM DEFAULT CHARSET=utf8;<br />INSERT INTO `test_user` VALUES (1,'admin',110);
class ProModel extends RelationModel{<br /><br /> protected $_link=array(<br /> 'Avatar'=>array(<br /> 'mapping_type'=>self::HAS_ONE,<br /> 'class_name'=>'Avatar',<br /> 'foreign_key'=>'uid',<br /> 'mapping_fields'=>'avatar',<br /> 'as_fields'=>'avatar',<br /> ),<br /> )<br />}
<br />class ProModelModel extends ViewModel { <br /> <br /> public $viewFields = array( <br /> 'test_avatar'=>array(<br /> 'id',...<br /> ), <br /> 'test_pror'=>array(<br /> 'id',...<br /> '_on'=>''<br /> ), <br /> 'test_pror'=>array(<br /> 'id',...<br /> '_on'=>''<br /> ), <br /> ); <br />}