CodeIgniter Forums

Full Version: Model's save method should scan for existing row
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
If you have a specific primary key but you know you want to create a new record, why not use insert()?