3.1.3 关联模型 BLONGS_TO

浏览:387 发布日期:2014/04/21 分类:求助交流 关键字: BLONGS_TO
求助BLONGS_TO
库设计


关键代码<?php                                                    
//用户与角色关联模型                                     
    Class UserRelationModel extends RelationModel{       
        //定义主表名称                                   
        Protected $tableName = 'user';                   
                                                                                        
        //定义关联关系                                                                  
        Protected $_link = array(                        
            'role' => array(                             
                'mapping_type' => MANY_TO_MANY,          
                'foreign_key'  => 'user_id',             
                'relation_key' => 'role_id',             
                'relation_table' => 'pthink_role_user',  
                'mapping_fields' => 'id,name,remark'     
            ),                                                                          
            'partment' => array(                          
                'mapping_type' => BELONGS_TO,            
                                                                                                          
                'foreign_key'  => 'id'                   
            ),                                                                          
        );                                                                              
    }                                                                                   
?>  
调用处            $this->user = D('UserRelation')->where('username="'.$_SESSION['username'].'"')->relation('partment')->select();                                               
            dump($this->user);die;
结果


不知道怎么关联,求指导

为了左证,我再传几个数据库字段内容
pthink_user表段内容


pthink_user_partment表段内容

pthink_partment表段内容


求指导,感谢
最佳答案
评论( 相关
后面还有条评论,点击查看>>