0

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!

version 2
  • 1,049
  • 3
  • 15
  • 36
  • @arilia Added code. – version 2 Jun 22 '17 at 10:14
  • @G.J Can you have a look at this? – version 2 Jun 22 '17 at 10:25
  • 1
    You may want to have a look at **https://stackoverflow.com/questions/26799094/how-to-filter-by-conditions-for-associated-models**, sounds like you want to filter by associated data. ps, you're mixing in CakePHP 2.x stuff, there is no `recursive` option in CakePHP 3.x anymore. – ndm Jun 22 '17 at 11:09

0 Answers0