![]() |
Hi, I have a weird problem, I don't know if I'm doing something wrong or it is a bug.
I have a soft delete for customers. CustomerModel and Customer Entity. Database field: customer_deleted: 1,0, NULL (Default:NULL) Code: PHP Code: This code update the date but does not set customer_deleted to NULL, it ignores it. If I use array instead of entity object, It works, updates date and set deleted = null PHP Code: Why passing data as entity object does not work? Maybe codeigniter ignore data = null when calling update()? Thank you
Why customer_deleted is null and customer_deleted_at is not null?
It does not make sense. Is it soft-deleted or not? And if you use soft-deletion, you should not change customer_deleted and customer_deleted_at like your code.
(12-29-2021, 05:43 PM)kenjis Wrote: Why customer_deleted is null and customer_deleted_at is not null? It just an example. Forget customer_deleted. Imagine I only use customer_deleted_at. How can I set it to NULL? Codeigniter query is "deleted_at IS NULL" when you call $model->findAll(), so you need to set that field = null but I don't know how to do it. If I do $customer->customer_deleted_at = NULL; and then $model->save($customer) (or update($customer)) It doesn't save/update. What need to do?
Do you want the soft-deleted record to be restored?
How about this? 1. Get the record with withDeleted() 2. Change the properties 3. Save it
You can pass an array instead of an entity.
PHP Code: $data = [
(12-30-2021, 04:34 AM)iRedds Wrote: You can pass an array instead of an entity. Yes, I know that array works, but Entity Object doesn't work, is a bug? (12-30-2021, 04:18 AM)kenjis Wrote: Do you want the soft-deleted record to be restored? I do that, but if I change properties passing data as object to save(), doesn't work. It only works with array. Is a bug?
If everything works with the array, then it will work with the entity.
PHP Code: class Model extends \CodeIgniter\Model
@AngelRodriguez
iRedds's code works. I don't know why you can't update.
(12-31-2021, 03:55 AM)kenjis Wrote: @AngelRodriguez Problem solved: My "Customer Entity" was: PHP Code: class Customer extends Entity Removing " => null", works: PHP Code: class Customer extends Entity |
Welcome Guest, Not a member yet? Register Sign In |