thinkphp 關聯模型配置代碼

<?php
/**
 * 公司與部門關聯模型
 */
class CompanyRelationModel extends RelationModel{
    
    //主表名稱
    protected $tableName = 'company';
    
    //定義關聯關係
    protected $_link = array(
            
        //關聯表名稱
        'department' => array(
            'mapping_type'        =>     MANY_TO_MANY,                //多對多關係
            'foreign_key'        =>    'company_id',                //主表外鍵
            'relation_key'        =>    'department_id',            //關聯表外鍵
            'relation_table'    =>    'sys_company_department',    //中間表(員工對應角色表),
            'mapping_fields'    =>     'id, name, pId'                //關聯表顯示字段
        )
    );
    
}
?>
相關文章
相關標籤/搜索