I want to update a model. I have a query like this
UPDATE mymodels SET `myfield` = 100 WHERE `id`=12 OR `id`=13 OR `id`=14
// also the same:
UPDATE mymodels SET `myfield` = 100 WHERE `id` IN (12,13,14)
And I tried this:
$this->MyModel->updateAll(
// fields
array('MyModel.myfield' => 100),
// conditions
array('MyModel.id' => 12)
);
But I need to update 20 different records.
Record ids are like this 12, 13, 14 ....
If the records you want to update are sequential, then try adding two conditions like this
$this->MyModel->updateAll(
array('MyModel.myfield' => 100),
// conditions
array('MyModel.id >=' => 12, 'MyModel.id <=' => 20)
);
If there's no relation between indexes of ids, try using an array
$this->MyModel->updateAll(
array('MyModel.myfield' => 100),
// conditions
array('MyModel.id' => array(12,13,14...))
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With