Scope User class

I’m trying to aleter the find() method of the User model to allow me to scope users to specific tenants for administration purposes. A tenant can only view and edit his own users. I have this working for other models, but I’m getting the error:

Invalid Configuration – yii\base\InvalidConfigException

User::identityClass must be set.

Error is occurring on the init of the UserQuery class at: Yii::$app->user->id;




class User extends BaseUser implements IdentityInterface

{

  

  ... Do Stuff...


  //supplant FIND with UserQuery

  public static function find()

  {

      return new UserQuery(get_called_class());

  }

}

 

 


class UserQuery extends ActiveQuery 

{

    public function init()

    {   

        $user_id = Yii::$app->user->id; //ERROR IS THROWN HERE

        $user = User::find(['id'=>$user_id])->one();

        $role = $user->role;

 

        if($role == 'tenent_admin'){

 

            //the tenent admin can see all models

            return $this->andWhere(['user.distributor_id' => $user_distributor_id]);

 

        }

            

    }

}