We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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?



47.7k
Accepted
answer

Where the default database value is NULL.

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


47.7k
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') ;
}


32.2k

Maybe:

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