sarvan75 / yii-user-management

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

User::hasRole('role') #10

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I tried to user role management but I've got an exception:

The relation "roles" in active record class "User" is not specified
correctly: the join table "" given in the foreign key cannot be found in
the database.

Original issue reported on code.google.com by christop...@gmail.com on 18 Mar 2010 at 6:45

GoogleCodeExporter commented 9 years ago
what is the result of usermodel->_userRoleTable ? It runs in User::relations().

It seems like the model is not able to determine the user_has_role table 
correctly.
try so lowercase the Yii:App() to Yii::app() in the sourcecode (fixed in next 
svn commit)

Your problems all occur with a non-default tablename. This is good, so the 
Module
gets tested well in this environment :)..

Original comment by thyseus on 18 Mar 2010 at 7:03

GoogleCodeExporter commented 9 years ago
Here the function relations of User :
public function relations()
    {
    if (isset(Yii::app()->controller->module->userRoleTable))
      $this->_userRoleTable = Yii::app()->controller->module->userRoleTable;
    elseif (isset(Yii::App()->modules['user']['userRoleTable']))
      $this->_tableName = Yii::App()->modules['user']['userRoleTable'];
    else
      $this->_userRoleTable = 'user_has_role';

        return array(
            'profile'=>array(self::HAS_ONE, 'Profile', 'user_id'),
            'roles'=>array(self::MANY_MANY, 'Role', $this->_userRoleTable . '(user_id, role_id)'),
            );
    }

And  $this->_tableName = Yii::App()->modules['user']['userRoleTable']; should 
be 
$this->_userRoleTable = Yii::App()->modules['user']['userRoleTable']; like the 
two
others !

Thanks

Original comment by christop...@gmail.com on 18 Mar 2010 at 7:28

GoogleCodeExporter commented 9 years ago
bug fixed in latest svn

Original comment by thyseus on 19 Apr 2010 at 7:15