Confused How To Mdify The Primarykey

Hi,

Can anyone explain which primary key used while fetching Model ?

http://www.yiiframework.com/doc/guide/1.1/en/database.ar#defining-ar-class

tells that we can modify the primaryKey of a Model

[size=2] [/size][size=2]public function primaryKey()[/size]

{


	return 'fk_user_id';


}

I found that the $model->tableSchema->primaryKey not the return the primary key set by the above method, it always return the primary key set in the table while creating it. which is used while fetching record and association like BELONGS_TO etc …

for example :

Profile::model()->setPrimaryKey(‘fk_user_id’);

echo Profile::model()->getPrimaryKey();

return the primary key as "sk_user_id" but while association like BELONGS_TO its not using it, rather using the primary key return by the

[size=2]Profile::model()[/size]->tableSchema->primaryKey !!!!!

can anyone help me out ?

Where did you put this code?




public function primaryKey() { 

    return 'fk_user_id'; 

}



in the Model of which i want to change the PK

Hi ,

your answer is inside

http://www.yiiframework.com/forum/index.php/topic/17708-overriding-primarykey/