Farzan
(Farzan B)
September 10, 2011, 6:59am
1
Hi,
I use the following code to update all rows in a table using Active Record:
$reader = User::model()->findAll();
foreach ($reader as $row) {
$row->fname = 'something';
$row->save();
}
But this updates only the last record. What is wrong?
Thank you.
Haensel
(Johannes)
September 10, 2011, 8:35am
2
Try to use
$row->save(false);
in order to disable model validation, just to make sure that this isn’t the problem. Maybe the last record you load via findAll() is the only one that has a “required” attribute already set, all others don’t.
dckurushin
(Diavolonok)
September 10, 2011, 9:12am
3
Just tested it with my Ar model , no problems… this should work
The only reason it can fail is the validation as Haensel mentioned
Farzan
(Farzan B)
September 10, 2011, 9:22am
4
Thank you!
You were right. The last record was the only valid one.