# Error 'Policy for Cake\\ORM\\ResultSet has not been defined' - authorization related

**URL:** https://discourse.cakephp.org/t/error-policy-for-cake-orm-resultset-has-not-been-defined-authorization-related/8669
**Category:** Need Help
**Created:** [November 30, 2020, 10:34am UTC](https://discourse.cakephp.org/t/error-policy-for-cake-orm-resultset-has-not-been-defined-authorization-related/8669 "2020-11-30T10:34:21Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![vale\_a](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/vale_a/32/2054_2.png) [@vale\_a](https://discourse.cakephp.org/u/vale_a)
#### Post date: [November 30, 2020, 10:34am UTC](https://discourse.cakephp.org/t/error-policy-for-cake-orm-resultset-has-not-been-defined-authorization-related/8669/1 "2020-11-30T10:34:21Z")

</div>

I’m new to CakePHP, just followed the CMS tutorial and trying to figure out how authorization component works.  
Auth on single Entity works fine, but when I create a table policy class for my Entity I don’t know how to implement the actions, this is the actual code:

class utentivaleTablePolicy  
{

```
public function canIndex(IdentityInterface $user, utentivale $utentivale)
{
    return true;
}
public function scopeIndex(IdentityInterface $user, utentivale $utentivale )
{
    return $user->role_id== $user::TYPE_ADMIN;

}

```

}

In the controller class, index method:  
public function index()  
{

```
    $utentivale = $this->paginate($this->Utentivale);

    $this->Authorization->authorize($utentivale);
   
    $this->set(compact('utentivale'));
}

```

When I go to localhost:8765/utentivale/ I receive the error  
_Error ‘Policy for Cake\ORM\ResultSet has not been defined’._

I must be missing something…  
Thanks for your help

---

<div class="post-metadata">

### Author: ![nicola.marte](https://avatars.discourse-cdn.com/v4/letter/n/71c47a/32.png) [@nicola.marte](https://discourse.cakephp.org/u/nicola.marte)
#### Post date: [March 8, 2021, 1:42pm UTC](https://discourse.cakephp.org/t/error-policy-for-cake-orm-resultset-has-not-been-defined-authorization-related/8669/2 "2021-03-08T13:42:07Z")

</div>

UP.

Same issue here. I would like to set authorization policy to the users controller, but i cannot figure out because i get stuck at " Policy for `Cake\ORM\ResultSet` has not been defined" error…

The example is the cms in the toturial. How can i set authorization to the view and index method?

A little help would be much appreciated, thanks in advance.

Nicola.

---

<div class="post-metadata">

### Author: ![vale\_a](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/vale_a/32/2054_2.png) [@vale\_a](https://discourse.cakephp.org/u/vale_a)
#### Post date: [March 8, 2021, 2:43pm UTC](https://discourse.cakephp.org/t/error-policy-for-cake-orm-resultset-has-not-been-defined-authorization-related/8669/3 "2021-03-08T14:43:59Z")

</div>

I resolved implemeting the scopeIndex functions in UsersTablePolicy in a different way:

public function scopeIndex(IdentityInterface $user, Query $query )  
{

```
 return $query->select(['field1','field2','fieldn']);

```

}

Check also in UserPolicy that canView is enabled:  
public function canView(IdentityInterface $user, User $resource)

```
{
        return true;
}

```

PS: these are examples, so you have to provide your own business logic

---

<div class="post-metadata">

### Author: ![yousuo](https://avatars.discourse-cdn.com/v4/letter/y/898d66/32.png) [@yousuo](https://discourse.cakephp.org/u/yousuo)
#### Post date: [June 2, 2021, 8:35am UTC](https://discourse.cakephp.org/t/error-policy-for-cake-orm-resultset-has-not-been-defined-authorization-related/8669/4 "2021-06-02T08:35:33Z")

</div>

For those you are searching. Based on [policy docs.](https://book.cakephp.org/4/en/tutorials-and-examples/cms/authorization.html)

Create/bake policy with ( **–type table** ) :

```auto
// note plural
bin/cake bake policy -v --type table Articles

```

Then add this in the newly created/baked `/src/Policy/ActiclesTablePolicy.php`

```auto
public function canIndex($user, $query)
{
   //return true or false;
}

```

```auto
// In controller
$this->Authorization->authorize($query);

```

---

<div class="post-metadata">

### Author: ![mainpal1](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/mainpal1/32/2373_2.png) [@mainpal1](https://discourse.cakephp.org/u/mainpal1)
#### Post date: [October 27, 2021, 3:02am UTC](https://discourse.cakephp.org/t/error-policy-for-cake-orm-resultset-has-not-been-defined-authorization-related/8669/5 "2021-10-27T03:02:58Z")

</div>

Here, you can do different things:

1. To send the Table class and accept “UtentivaleTable” object as the second parameter in the policy’s canIndex function:  
// In controller’s index() action  
$this-\>Authorization-\>authorize($this-\>Utentivale);

// In policy class:  
public function canIndex(IdentityInterface $user, UtentivaleTable $utentivale)  
{  
return true;  
}

1. To send the query and accept Cake\ORM\Query object as the second parameter in the policy’s canIndex function:  
// In controller’s index() action  
$query = $this-\>Utentivale-\>find();  
$this-\>Authorization-\>authorize($query);  
$utentivale = $this-\>paginate($query);

// In policy class:  
public function canIndex(IdentityInterface $user, Cake\ORM\Query $query)  
{  
return true;  
}

There could be more solutions available. But, haven’t tried anything else.  
Hope this works.

Thank you!
