-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling update() with an Entity throws an error #4143
Comments
This is happening because on I think that this is the desired design for this method, so I would suggest making small changes to your view. <input type="hidden" name="id" value=<?=$data->id?>>
<input type="hidden" name="active" value="0">
<input type="checkbox" name="active" value="1" <?=$data->active ? 'checked' : ''?> > class Test extends Entity
{
protected $attributes = [
'active' => null,
];
} This way, the |
@michalsn It works but if I change the position of the html suppose that I invert the lines it would stop working correctly because they are repeated names, it takes the last value to be found within the html I understand how update works internally, I think it created confusion when using it in this type of case, it would be a good idea maybe to add to the documentation that only updates the fields that detect a change in the case of using entities. or if the user prefers, specify explicitly with set() thanks for answering! |
@luispastendev Yes, the correct order for inputs is necessary to do the trick here. It's not the only way to deal with it, I guess calling I see we're already mentioning in the user guide that Entities are working this way but only for |
thank you very much michalsn :) |
Describe the bug
suppose I have the following example:
If the checkbox is not activated, no key arrives in the request so I assign a default value in an entity
Now I fill the entity and proceed to save the change, if the value is set active it works perfectly but when no value is sent and it is about saving the default value 0 of the entity it sends the following error
I have solved it using it in the following way but with the update() method as shown in the documentation that problem is found
Thank you very much team!
CodeIgniter 4 version
dev develop
Affected module(s)
model update()
Expected behavior, and steps to reproduce if appropriate
The registry must be updated when you use entities with default values
Context
The text was updated successfully, but these errors were encountered: