Welcome Guest, Not a member yet? Register   Sign In
Model Update ignores null
#1

(This post was last modified: 12-29-2021, 08:12 AM by AngelRodriguez.)

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:
 
$customerModel 
= new CustomerModel();
 $customer = new Customer();
$customer->customer_deleted null;
$customer->customer_deleted_at date('Y-m-d H:i:s');
 
$customerModel->update($customer_id$customer); 

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:
 
 $customerModel 
= new CustomerModel();
$array = [
     
'customer_deleted' => null,
     
'customer_deleted_at' => date('Y-m-d H:i:s')
 ];
$customerModel->update($customer_id$array); 
 

Why passing data as entity object does not work?
Maybe codeigniter ignore data = null when calling update()?

Thank you
Reply


Messages In This Thread
Model Update ignores null - by AngelRodriguez - 12-29-2021, 08:10 AM
RE: Model Update ignores null - by kenjis - 12-29-2021, 05:43 PM
RE: Model Update ignores null - by AngelRodriguez - 12-30-2021, 03:18 AM
RE: Model Update ignores null - by kenjis - 12-30-2021, 04:18 AM
RE: Model Update ignores null - by iRedds - 12-30-2021, 04:34 AM
RE: Model Update ignores null - by AngelRodriguez - 12-30-2021, 05:08 AM
RE: Model Update ignores null - by iRedds - 12-30-2021, 03:49 PM
RE: Model Update ignores null - by kenjis - 12-31-2021, 03:55 AM
RE: Model Update ignores null - by AngelRodriguez - 01-03-2022, 06:13 AM



Theme © iAndrew 2016 - Forum software by © MyBB