Confused How To Mdify The Primarykey


Can anyone explain which primary key used while fetching Model ?

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 :


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