yii2与多个表连接

问题描述 投票:0回答:1

我正在使用kartik gridview,我想使用joinwith多个表来显示结果页面。下面我使用select语句来获取输出,我需要在选择查询的索引页面(以粗体突出显示)中显示

$query = EmpDetails::find()->joinWith(['employeeStatutoryDetail'])
            ->where(['NOT IN', 'emp_statutorydetails.gpa_no', ['']])
            ->orWhere(['IS NOT', 'emp_statutorydetails.gpa_no', NULL]);

我的查询:

SELECT A.empcode,A.empname,
       B.designation,
       C.division_name,
       D.gpa_no,D.gpa_sum_insured,
       E.fellow_share
  FROM emp_details AS A JOIN designation 
                   AS B JOIN division 
                   AS C JOIN emp_statutorydetails 
                   AS D JOIN vg_gpa_hierarchy 
                   AS E JOIN vg_gpa_policy 
                   AS F ON F.policy_no=D.gpa_no 
  WHERE D.empid=A.id AND 
        A.designation_id=B.id AND 
        A.division_id=C.id AND 
        E.sum_insured=D.gpa_sum_insured
yii2 jointable
1个回答
0
投票

要为EmpDetails建模,请添加其他属性名称,division_name,gpa_no,gpa_sum_insured和fellow_share。对于搜索和排序建议创建扩展模型EmpDetailsS​​earch。

© www.soinside.com 2019 - 2024. All rights reserved.