gavin1420 / yii-user

Automatically exported from code.google.com/p/yii-user
0 stars 0 forks source link

Relation errors when lookup table does not have "id" as Pk #74

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a relation table as per these instructions, 
http://code.google.com/p/yii-user/wiki/FieldWidget#Add_relation_to_Country_model
 , however give the relation table a Pk other than "id", eg. "idCountry"
2. Go to User Admin, click "Create User"

What is the expected output? What do you see instead?
Expected: a new user data form. Actual: Handled error "Property <tablename>.id 
is not defined.".

What version of the product are you using? On what operating system?
yii-1.1.6.r2877, yii-user-0.3-r107

Please provide any additional information below.
After investigating this issue, I found that user.components.UWrelBelongsTo has 
an issue on line 73.

$list[$m->id] = 
(($this->params['optionName'])?$m->getAttribute($this->params['optionName']):$m-
>id);

My solution was to change the direct reference to id, to the accessor method 
getPrimaryKey.

$list[$m->getPrimaryKey()] = 
(($this->params['optionName'])?$m->getAttribute($this->params['optionName']):$m-
>getPrimaryKey());

Original issue reported on code.google.com by steven.j...@gmail.com on 19 Mar 2011 at 1:27