CodeIgniter Forums
How to skip no data to update exception? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: How to skip no data to update exception? (/showthread.php?tid=84609)



How to skip no data to update exception? - Jag81 - 10-26-2022

Hi, 
is there a way to skip the "no data to update" exception?

I use this line to save:
PHP Code:
$model->save($entity); 

Often the entity is new, but sometimes the entity is known and not changed.

I need this behavior: If there is something changed the update, if not, continue (without firing an exception).


RE: How to skip no data to update exception? - kenjis - 10-26-2022

try/catch.

v4.3.0 will have allowEmptyInserts() method.


RE: How to skip no data to update exception? - Jag81 - 10-26-2022

(10-26-2022, 04:25 AM)kenjis Wrote: try/catch.

v4.3.0 will have allowEmptyInserts() method.

Do you mean to leave the catch empty,  something like this?
PHP Code:
try{
  $model->save($entity);       
} catch (\Exception $e) {
    // LEAVE THIS EMTPY
}

//other stuff that will be processed even when an Exception is fired.