can anybody help me to join 2 tables.
i have tbl_a(id, name) and tbl_ab(temp, uid, born)
in tbl_a, id is primary key,
in tbl_b, temp is primary key
and uid is foreignkey which refers id oftbl_a.
i have my code like,
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'id' => array(self::BELONGS_TO, 'tbl_one', 'id'),
'name' => array(self::BELONGS_TO, 'tbl_one', 'name'),
);
}
here tbl_one is my model name of table tbl_a
in view/admin i written like
<?php $this->widget(‘zii.widgets.grid.CGridView’, array(
'id'=>'tbl-two-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'temp',
array('name'=>'id', 'value'=>'$data->tbl_one->id'),
array('name'=>'name', 'value'=>'$data->tbl_one->name'),
'uid',
'born',
array(
'class'=>'CButtonColumn',
'template'=>'{view}'),
),
)); ?>
and in tbl_two.php(model) i have search function like
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->alias = 'i';
$criteria->compare('temp',$this->temp);
$criteria->compare('uid',$this->uid,true);
$criteria->compare('born',$this->born,true);
$criteria->join= 'JOIN tbl_ab d ON (i.uid=d.uid)';
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
i am not getting the output. getting error like:
Property "tbl_two.tbl_one" is not defined.
can anybody help me to resolve this plz soon…