function insertRows(RM_Extras_Row $extra, array $unitIDs) { $this->delete('extra_id=' . $extra->id); //remove old values if ($unitIDs[0] == 0) { //all units $extra->global = 1; $extra->save(); return true; } elseif ($extra->global == 1) { $extra->global = 0; $extra->save(); } foreach ($unitIDs as $unitID) { $this->createRow(array('extra_id' => $extra->id, 'unit_id' => $unitID))->save(); } }