I’m stuck with an issue and i need your help, i want to use CdbCriteria with relations already defined in model related.
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
.....
For example, i want to replace user_id (current model ) with username (other model )
using relation’s section Is that possible ??
Post Model :
Post_Id
Post_Title
......
User Model :
user_Id
username
......
in my current model ( PostUser Model )
....
Post_Id
User_Id
I want to replace userId by username using relation "user".
My table contains 4 attributes ( see attributeLabels) with 2 foreign keys (see relations )
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(
'collaborateur' => array (self :: BELONGS_TO,'Collaborateur','collaborateurID'),
'typeJourConge' => array (self :: BELONGS_TO,'Typejourconge','typeJourCongeID'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array (
'DateJourCongeF' => 'DateJourCongeF',
'DateJourCongeD' => 'DateJourCongeD',
'collaborateurID' => 'collaborateur',
'typeJourCongeID' => 'typeJourConge',
);
}
But when i open the generated file, collaborateurID and typeJourCongeID contains numbers ( foreign key ), But what i’m trying to do since 3h, is to get collaborateurName in place of collaborateurID using relation collaborateur.