I have an array of active records and want to change some field of them with a loop in this manner:
$error = false;
foreach ($items as $item) {
$item->is_paid = self::PENDING;
$error = $error || !$item->save();
}
return $error;
What I want to do is to change the is_paid
property for all of this items. If on fails, roll back the others. How can I use transaction to solve this problem?