Issue
I got a strange behaviour using the notMatching function of the query builder in combination with a standard where. The parameters given in OR/AND arrays seems to be mismatched (more precisely it seems to take the last one and use it for the pre-last one).
Here is my query:
$myModel
->find('list')
->where(['column' => 'a value to match']) // If I remove the entire line it works
->notMatching('AnotherModel', function ($query) use ($value, $anotherValue) {
return $query->where([
'OR' => [
['secondColumn >=' => $value],
['secondColumn <=' => $value]
],
'thirdColumn' => $anotherValue
]);
});
And here is the generated SQL (simplified):
`column` = `a value to match`
AND (
`MyModel`.`id` NOT IN (
SELECT
...
FROM
...
WHERE
(
(
`secondColumn` >= $value
OR `secondColumn` <= $anotherValue /* The issue */
)
AND `thirdColumn` = $anotherValue
)
)
)
As you can see, $anotherValue is used instead of $value. If I remove the entire first where (after the find) it works as excepted. And interestingly I don't have the issue with matching or innerJoinWith.
Solution
This seems to be fixed in CakePHP version 3.8.12
Answered By - randomUserName
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.