Hi,
I am new to Yii and i want to set the primary key of my Model after creating the Model with "gii". here is the description,
I am using MySql and [size="2"]I have created a model "Profile" with "id" as Auto incremented. [/size][size="2"]But after creating model i found that i should make field "fk_user_id" be the PK so what i did that i have added a function [/size]
[size=“2”]public function primaryKey()[/size][size=“2”]{[/size][size=“2”] return ‘fk_user_id’;[/size][size=“2”]} [/size] [size=“2”]to the model “Profile” but which should return the primary key of the model and it does through echo Profile::model()->getPrimaryKey() in the Profile model which returns ‘fk_user_id’, [/size] [size=“2”]But while performing the join with a Model “Friend” where Friend has a relation [/size] [size=“2”]Relation of model Friend[/size]
public function relations()
{
return array(
‘user’=>array(self::BELONGS_TO, ‘User’, ‘fk_friend_user_id’),
‘profile’=>array(self::BELONGS_TO, ‘Profile’, ‘fk_friend_user_id’),
‘friendList’ => array(self::MANY_MANY, ‘FriendList’, ‘tbl_friend_friend_list_assoc(fk_friend_id, fk_friend_list_id)’),
);
}
after that while fetching the Friend record i am not able to get the related Profile data
[b]public function actionIndex($id)[/b]
{
$criteria=new CDbCriteria;
$criteria->with = array("profile");
$criteria->condition = "t.fk_user_id=".$id;
$dataProvider=new CActiveDataProvider(‘Friend’, array(
‘criteria’=>$criteria,
));
$this->render(‘index’,array(
‘dataProvider’=>$dataProvider
));
}
I have noticed that if i make the fk_user_id as primary key in the table structure its getting the related Profile data!
i have attached the table schema screen shots
Can someone help me ?
Thanks in advance