Hi everyone,
I have a question regarding the updateAll() function.
I use it to reduce or increase credits (not surprisingly) but I have
an issue: how can I be sure that all went well. What I mean:
I have a method reduceCredits($id, $amount), which is like that:
return $this->updateAll(
array(
'Manager.credit' => "Manager.credit-{$amount}"
),
array(
'Manager.id' => $id,
'Manager.credit >= ' => $amount
)
);
So, if the operation is OK, I want to proceed as normal. But before I
call reduceCredits(), I validate the operation, checking if there are
enough credits, i.e. I read the record of the Manager and check the
Manager.credit field. Now, if the validation passes, but someone else
gets some of the credits before the calling of the reduceCredits()
function, it might not reduce credits because of the 'Manager.credit
>= ' => $amount condition (i.e. the credits are now below the
$amount). So a statement like:
if($this->Manager->reduceCredits($id, $amount))
always returns TRUE no matter if the record gets updated or not. So
the question here is: how can I know for sure if the update actually
took place or not.
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en