# Cakephp3- unable to fetch all acos for an aros

**URL:** <https://discourse.cakephp.org/t/cakephp3-unable-to-fetch-all-acos-for-an-aros/2761>\
**Category:** Need Help\
**Created:** [June 22, 2017, 4:45am UTC](https://discourse.cakephp.org/t/cakephp3-unable-to-fetch-all-acos-for-an-aros/2761 "2017-06-22T04:45:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![themarsbeing](https://avatars.discourse-cdn.com/v4/letter/t/85e7bf/32.png) [@themarsbeing](https://discourse.cakephp.org/u/themarsbeing)\
**Post date:** [June 22, 2017, 4:45am UTC](https://discourse.cakephp.org/t/cakephp3-unable-to-fetch-all-acos-for-an-aros/2761/1 "2017-06-22T04:45:53Z")

</div>

I’m trying to fetch all acos for a given aros.

Cakephp version I’m using is 3.4

As ACL is not built-in I use this [plugin](https://github.com/ivanamat/cakephp3-aclmanager).

I’m able to fetch all acos available by using this code:

```
   $acos = $this->Acl->Aco->find('all', array('order' => 'Acos.lft ASC', 'recursive' => -1))
           ->contain(['Aros']) 
           ->toArray();

```

And, following is the code I wrote to fetch all acos for a given aros

```
 $acos = $this->Acl->Aco->find('all', array('order' => 'Acos.lft ASC', 'recursive' => -1))
       ->contain(['Aros' => function ($q) {
                    return $q->where(['id' => 1]);
                } ]) 
       ->toArray();

```

But it does not return the correct result. Instead, it returns all the acos (the same result the above code returns)

Can anyone help me identify the issue? Thanks!

---

<div class="post-metadata">

**Author:** ![themarsbeing](https://avatars.discourse-cdn.com/v4/letter/t/85e7bf/32.png) [@themarsbeing](https://discourse.cakephp.org/u/themarsbeing)\
**Post date:** [June 22, 2017, 11:13am UTC](https://discourse.cakephp.org/t/cakephp3-unable-to-fetch-all-acos-for-an-aros/2761/2 "2017-06-22T11:13:33Z")

</div>

Is there a way to do this?

---

<div class="post-metadata">

**Author:** ![riddlemd](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/riddlemd/32/643_2.png) [@riddlemd](https://discourse.cakephp.org/u/riddlemd)\
**Post date:** [June 23, 2017, 5:26pm UTC](https://discourse.cakephp.org/t/cakephp3-unable-to-fetch-all-acos-for-an-aros/2761/3 "2017-06-23T17:26:35Z")

</div>

Look into the [matching](https://book.cakephp.org/3.0/en/orm/query-builder.html#filtering-by-associated-data) method in the QueryBuilder
