Cakephp3- unable to fetch all acos for an aros


#1

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.

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!


#2

Is there a way to do this?


#3

Look into the matching method in the QueryBuilder