Welcome Guest, Not a member yet? Register   Sign In
DataException: There is no data to update after using save()

I would like to discuss a very common situation that often arises:

1. A user updates their profile information in a form on the view page.
2. The controller receives the posted data, fills the profile entity with the new (or not) information using the `fill()` method, and then saves the data.
3. However, there is a concern with this procedure. When using `CodeIgniter\Entity\Entity::class`, only the attributes that have changed are updated. Therefore, if the user clicks the "Update" button without making any changes, a `DataException` is triggered with the message "There is no data to update."

In my opinion, this limitation renders entities almost useless for this type of workflow. Since we cannot determine beforehand if all the attributes of the `CodeIgniter\Entity\Entity` are the same as the original, there isn't much we can do to prevent this from happening. My question is: is this intended behavior? Shouldn't entities be able to return true even if nothing has changed?

We already have `$model->allowEmptyInserts()->insert([]);`, why not provide also both `$model->allowEmptyUpdates()->update([]);` and `$model->allowEmpty()->save([]);`?

Please enlighten me if a better workflow can be used in this case.



Messages In This Thread
DataException: There is no data to update after using save() - by bgeneto - 05-26-2023, 07:35 AM

Theme © iAndrew 2016 - Forum software by © MyBB