The resolution by kiran sharma works well.What i do not understand i wrote in comments:
Encomenda Model
<?php
class EncomendaLinha extends CActiveRecord
{
public $artist; //why do you have to declare this two attribute if these are declared on
public $title; // relation 'ritmo'
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return EncomendaLinha the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'encomenda_linha';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('encomenda', 'required'),
array('style, encomenda', 'numerical', 'integerOnly'=>true),
array('gender, driver_job_style, industries, license, endorsement, artist, title','safe'), // i dont know what safe does and
//why is repeated on search scenario
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('idencomenda_linha, style, encomenda, artist, title', 'safe', 'on'=>'search'),
);
}
/**
* @return array relational rules.
*/
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(
'encomenda' => array(self::BELONGS_TO, 'Encomenda', 'encomenda'),
'ritmo' => array(self::BELONGS_TO, 'Ritmo', 'style'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'idencomenda_linha' => 'Idencomenda Linha',
'style' => Yii::t('app','Style'),
'encomenda' => 'Encomenda',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
Yii::import('application.modules.admin.models.*');
$criteria=new CDbCriteria;
$criteria->with = array( 'encomenda','ritmo' ); //yes i understand the join but why encomenda??
$criteria->compare('idencomenda_linha',$this->idencomenda_linha);
$criteria->compare('style',$this->style);
$criteria->compare('encomenda',$this->encomenda);
$criteria->compare('ritmo.artist',$this->artist,true); //-// added
$criteria->compare('ritmo.title',$this->title,true); //-// added
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
}
View file:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'encomenda-linha',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array('name'=>'artist',//this name is the name of the attribute created?
'header'=>'Artist',
'value'=>$data->ritmo->artist), // i had to insert '' here to work and why $data??
array('name'=>'title',
'header'=>'Title',
'value'=>$data->ritmo->title),
array(
'class'=>'CButtonColumn',
),
),
)); ?>