Yii: Double database table prefix error in yii-user-management

Important note: this applies to yii-user-management extension V0.7. This probably have already been fixed but not yet released. This is a quick fix if you don’t want to download the trunk.

If database prefix has been defined in config file, when accessing something in the module, eg Yii::app()->user->hasRole(), the following error is encountered:

The table “ext_ext_roles” for active record class “YumRole” cannot be found in the database.

This can happen to any tables used by the module.

It seems like it’s caused by table names returned by models. Without going into too much detail, which I don’t fully understand anyway, I noticed YumHelper::resolveTableName() is used when trying to reference tables. I believe this is used to handle user defined table names in config file.

By running some debug messages in this function, It seems that it’s trying to prefix table names with {{table_name}}, which is already prefixed.

For a quick fix, locate file /path/to/modules/user/core/YumHelper.php, add the following code to the beginning of the function:

public static function resolveTableName($tablename, CDbConnection $connection=null)
    if (substr($tablename, 0, 2) == '{{')
        return $tablename;

    // original function code....

Hopefully this is fixed in the next release.

Leave a Reply

Your email address will not be published. Required fields are marked *