And then in the where I don’t know how to place it as the CONCAT returns a function expression so I can’t simply do [$concat . ' LIKE' => '%inputString%]. I tried the like() function but wasn’t successful either:
->where('OR' => [$concat->like($concat => '%inputString%')]) // Illegal array key type
Can someone point me to the place where this is documented in here?
If it is not there, I really feel that such things should be present in the documentation. I found answers to this question for the laravel query builder but not cakephp so I’d be very grateful for some help.
Note, I’m only using the database module from the cake framework (not the ORM).
And my preferred solution would be without the need for the $query instance at all like
What you are misunderstand here is the difference between strings and identifiers
You have to tell CakePHP, that 'client.first_name' is not a string but an identifier for that table you are querying.
Thank you for the answer, Kevin.
Is there a way to use this concat outside the ->where() function ?
I’m building the where array outside the repository class that makes the request. toArray() does not work for me: Method 'toArray' not found in \Cake\Database\Query .
If I do
App\Domain\Client\Service\ClientFilterWhereConditionBuilder::App\Domain\Client\Service\{closure}():
Argument #2 ($query) must be of type Cake\Database\Query,
Cake\Database\Expression\QueryExpression given, called in
\vendor\cakephp\database\Expression\QueryExpression.php on line 719
I just had to change the $query->expr() to $query->newExpr() is that because I only use the Query Builder? But anyway, I’m happy. Thank you so much for the help!