I'm doing a query where i also want to retrieve associated data with the Contain argument.
The Contain subquery must be conditioned because i want only certain data, i followed Passing Conditions to Contain but i want to send a variable too and thats when i get this error:
Warning (2): Missing argument 2 for App\Controller\Admin\UsuariosController::App\Controller\Admin{closure}(), called in /opt/lampp/htdocs/faindit/vendor/cakephp/cakephp/src/ORM/Association/SelectableAssociationTrait.php on line 54 and defined [APP/Controller/Admin/UsuariosController.php, line 212]
and this:
Notice (8): Undefined variable: rol [APP/Controller/Admin/UsuariosController.php, line 217]
The variable is defined but the Cointain function is not receiving it. Which is the proper way to do this??
$rol = 1;
$countRoles = $rolesTable->find('all', [
'order'=>'Roles.nombre asc'
])->contain([
'Usuarios'=> function($q, $rol){
return $q
->select(['Usuarios.rol_id'])
->where([
'Usuarios.estado'=>$rol
]);
}
])->toArray();