Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to save database null to the database through the model

Hi,

I have a model that has a database field that is a blob.

When in the action controller I do:

database_record->my_blob = null;

Then an empty blob gets saved to the database.

How do I save null to the database in my nullable column?



24.5k
Accepted
answer

Where the default database value is NULL.

database_record->my_blob = new \Phalcon\Db\RawValue('default');


24.5k
edited Apr '15

So I don't have to write this in my action controller in my model I write:

public function beforeUpdate()
{
    $this->my_blob == null ?: new \Phalcon\Db\RawValue('default') ;
}


20.7k

Maybe:

new Phalcon\Db\RawValue('NULL');