We have successfully upgraded from CakePHP 3.10 to CakePHP 4.0 and currently in the process of migrating to 4.0 as per the 4.0 Migration Guide.
One of the major change that we noticed in 4.0 is that the finder functions in the Behavior now only allows query as the return type. We have many shared finder functions inside the Behavior (like the one below) which process the query and return the array, string or bool (Before upgrade they work just fine).
public function findUserModules(Query $query,array $options){
$activeModules = [];
$userSubscriptions = $query->where(['user_id' => $options['id']])->first();
if (!empty($userSubscriptions)) {
...
$activeModules = $userSubscriptions['active'];
}
return $activeModules;
}
These functions are now throwing the error:
2022-04-07 09:54:16 Error: [TypeError] Return value of Cake\ORM\BehaviorRegistry::callFinder() must be an instance of Cake\ORM\Query, array returned in .../vendor/cakephp/cakephp/src/ORM/BehaviorRegistry.php on line 275
I understand that we would have to update the finder functions to normal mixin methods. However, it requires major update throughout the application. I would like to know if there’s any work around to allow a different return type for the finder functions.