0

嗨,主人,我有 4 张桌子

-pegawai -penilaian -universitas -jurusan

我通常使用

    SELECT  u.nama_univ, j.singkatan, peg.* FROM pegawai AS peg LEFT JOIN penilaian AS pen ON pen.no_test=peg.no_test LEFT JOIN universitas AS u ON u.id=peg.univ_s1 LEFT JOIN jurusan AS j ON j.id=peg.bidang_s1

如何将此查询转换为 yii ?

我已经尝试过这段代码,但效果不佳

$dataProvider = new CActiveDataProvider('Pegawai', array(
    'criteria' => array(
        'select' => array(
            '`pen`.*',
            '`u`.`nama_univ` AS `nama_univ`',
            '`j`.`singkatan` AS `singkatan`'
        ),
        'join' => 'JOIN `Penilaian` AS `pen` ON `pen`.`no_test` = `t`.`no_test`',
        'join' => 'JOIN `Universitas` AS `u` ON `u`.`id` = `t`.`no_test`',
        'join' => 'JOIN `Jurusan` AS `j` ON `j`.`id` = `t`.`no_test`',
    )
));

但只有一个 join 有执行

4

2 回答 2

0

做一件事,您只需打印标准对象,例如

$dataProvider = new CActiveDataProvider('Pegawai', array(
    'criteria' => array(
        'select' => array(
            '`pen`.*',
            '`u`.`nama_univ` AS `nama_univ`',
            '`j`.`singkatan` AS `singkatan`'
        ),
        'join' => 'JOIN `Penilaian` AS `pen` ON `pen`.`no_test` = `t`.`no_test`',
        'join' => 'JOIN `Universitas` AS `u` ON `u`.`id` = `t`.`no_test`',
        'join' => 'JOIN `Jurusan` AS `j` ON `j`.`id` = `t`.`no_test`',
    )
));
echo "<pre>";
print_r($dataProvider);   //Check the object or try to post it below
exit();
于 2014-03-01T06:17:40.797 回答
0

您已将 3 个值分配给数组 ('join') 的同一索引,因此仅存储最后一个值。

尝试:

$dataProvider = new CActiveDataProvider('Pegawai', array(
'criteria' => array(
    'select' => array(
        '`pen`.*',
        '`u`.`nama_univ` AS `nama_univ`',
        '`j`.`singkatan` AS `singkatan`'
    ),
    'join' => 'JOIN `Penilaian` AS `pen` ON `pen`.`no_test` = `t`.`no_test` JOIN `Universitas` AS `u` ON `u`.`id` = `t`.`no_test` JOIN `Jurusan` AS `j` ON `j`.`id` = `t`.`no_test`',
)
));
于 2014-03-02T19:02:49.490 回答