Issue
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 ....
Solution
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...))
);
Answered By - Nunser
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.