Question

I do not fully know yii framework. How to make CDbCriteria for cases like this? I have a basic query code like this.

SELECT
jam_kerja.id,
jam_kerja.id_cabang,
jam_kerja.tgl_berlaku,
jam_kerja_detail.id_jam_kerja,
jam_kerja_detail.shift,
jam_kerja_detail.jamkerja,
jam_kerja_detail.jamistirahat
FROM
jam_kerja ,
jam_kerja_detail
WHERE
jam_kerja_detail.id_jam_kerja =  jam_kerja.id and  jam_kerja.id_cabang=5

Maybe there Yii friends who can help me?

Was it helpful?

Solution

$criteria = new CDbCriteria();
$criteria->select = 't.id,t.id_cabang, t.tgl_berlaku, jd.id_jam_kerja, jd.shift ,jd.jamkerja,';

$criteria->join = 'INNER JOIN jam_kerja_detail jd ON t.id = jd.id_jam_kerja'; 

$criteria->addCondition('t.id_cabang=5'); // edited this line

//and now give this criteria to your model

$model = YourModel::model()->findAll($criteria);

OTHER TIPS

I finally found the solution, it may be useful to other friends.

$criteria=new CDbCriteria;
$criteria->join='INNER JOIN jam_kerja t1 ON t1.id=t.id_jam_kerja';
$criteria->condition='t1.id_cabang='.$_GET['id'];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top