Question

hi master i've 4 tables

-pegawai -penilaian -universitas -jurusan

I usually use

    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

how to convert this query to yii ?

i've tried this code but it's not working well

$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`',
    )
));

but only one join there's execute

No correct solution

OTHER TIPS

Do one thing you just print the criteria object like

$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();

You have assigned 3 values to the same index of array ('join') so only the last one is stored.

Try:

$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`',
)
));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top