I came across a particular piece of cake 2 code in which the “where” clause accepts an array of values for a “greater than or equals to” (>=) clause.
Let me illustrate what I am talking about with the code below:
// this variable represents amounts due associated with an order
$transaction_amount_due = array(50,120, 39);
$conditions['Order.amount_due'] = '>= ' . $transaction_amounts_due ;
My question, is there a similar convention for cake4 queries?
What is that even supposed to return? What does it mean for something to be greater than three things?
The original code is generating the “where” Clause:
WHERE Order.amount_due >= 50 OR Order.amount_due >= 120 OR Order.amount_due >= 39
It’s kind of a meaningless way to build a query, though, right? It’s exactly equal to
WHERE Order.amount_due >= 39, which means your fix might be
$conditions['Order.amount_due >='] = min($transaction_amounts_due);
You are absolutely right! This cake2 code is pretty weird and at times has many of these poorly thought-out logic code pieces. I was still curious if there was any cake4 convention that would handle a query with these parameters automatically (as cake2 appeared to do).
Not that I’m aware of, but then I haven’t exactly gone looking for something like that…