Reputation: 433
I want to update one column which is an INT with a NULL value. I'm using CakePHP 2.3 with the saveField('field', 'value') method.
Here is my code :
$this->Customer->id = $customer_id;
if ($this->Customer->saveField('account_id', 'NULL')) {
//Do some stuff
}
So when I put 'NULL', the row is updated to 0. I tried NULL without quotes and the row is not updated.
EDIT : The field in the db accepts NULL value.
Do you have any idea ?
Thanks
Upvotes: 2
Views: 4329
Reputation: 154
I've had a similiar problem caused by a Upload Behaviour that had validations preventing the saving. Check your models, it might help. I assume saveField returns true even when validation rules prevent saving.
Upvotes: 1
Reputation: 5001
Do not pass 'NULL'
as a string but as null
value:
if($this->Customer->saveField('account_id', null))
{
//do some stuff
}
else
{
//do you get anything here ?
debug($this->Customer->validationErrors);
}
Upvotes: 3