CodeIgniter Forums
Model's save method should scan for existing row - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forum-29.html)
+--- Thread: Model's save method should scan for existing row (/thread-77376.html)



Model's save method should scan for existing row - NaufalA - 08-23-2020

save method was supposed to simplify logic to choose between insert/update, by scanning if row exist on the table or not. But as of right now, CodeIgniter 4.0.4, it only scans if table's primary key was mentioned on the input parameter.

So it will get confused when I want to insert a new data into a row with the primary key included. It will choose to update the data, because of the primary key which was included in the data, but fail to do so as the data itself is not there in the first place.

So I thought save method should look if inputted data was on the table to decide which method to use afterwards, insert or update.


RE: Model's save method should scan for existing row - MGatner - 08-26-2020

If you have a specific primary key but you know you want to create a new record, why not use insert()?