mdmsoft / yii2-admin

Auth manager for Yii2 (RBAC Manager)
GNU General Public License v3.0
1.16k stars 574 forks source link

Unable to establish relationship between User & AuthItem #262

Open senguttuvang opened 8 years ago

senguttuvang commented 8 years ago

I have this code in my User model

    public function getRoles() {
        return $this->hasMany(\mdm\admin\models\AuthItem::className(), ['name' => 'item_name'])
          ->viaTable('rbac_auth_assignment', ['user_id' => 'id']);
    }

`PHP Warning – yii\base\ErrorException

Missing argument 1 for mdm\admin\models\AuthItem::find(), called in /project/vendor/yiisoft/yii2/db/BaseActiveRecord.php on line 383 and defined

  1. in /project/vendor/mdmsoft/yii2-admin/models/AuthItem.php at line 138
  2. in /project/vendor/mdmsoft/yii2-admin/models/AuthItem.php at line 138 – yii\base\ErrorHandler::handleError(2, 'Missing argument 1 for mdm\admin...', '/project/vendor/mdms...', 138, ...) 132133134135136137138139140141142143144 /* * Find role * @param string $id * @return null|\self / public static function find($id) { $item = Yii::$app->authManager->getRole($id); if ($item !== null) { return new self($item); }
  3. in /project/vendor/yiisoft/yii2/db/BaseActiveRecord.php at line 383 – mdm\admin\models\AuthItem::find()
  4. in /project/common/models/User.php at line 216 – yii\db\BaseActiveRecord::hasMany('mdm\admin\models\AuthItem', ['name' => 'item_name']) 210211212213214215216217218219220221222 { return $this->getPrimaryKey(); }

    public function getRoles() { return $this->hasMany(\mdm\admin\models\AuthItem::className(), ['name' => 'item_name']) ->viaTable('rbac_auth_assignment', ['user_id' => 'id']); }

    /**

    • @inheritdoc */
  5. in /project/vendor/yiisoft/yii2/db/BaseActiveRecord.php at line 1143 – common\models\User::getRoles()`
mdmunir commented 8 years ago

Since the 'mdm\admin\models\Authitem' is not active record. You cannot do that. Create your own Authitem model

senguttuvang commented 8 years ago

Will I be able to extend your AuthItem class and establish relationship to that? How does it add / modify rows, if it is not ActiveRecord model? Is it framework's core AuthManager library that handles all that?

I had to filter users based on their roles [fortunately, one one role] so I went with join and did that. But, I'm looking for a ORM solution.