[SOLVED] AR: setAttribute


I only want to save my record.

One paramter should be NULL



$bw->comment = NULL;

[/indent]doesn’t work

Trying set attribute


$bw->setAttribute('comment', NULL);

[/indent]also doesn’t work.

Where am I wrong ?

(Comment is a colum of the AR class, $bw is an instance …)



[indent] [/indent]

I don’t know if this makes a difference, but I save null values successfully by assigning the value to ‘null’ in all lower-case.

Make sure that you don’t overwrite the attributes before you save them with something like


Also make sure the database ‘column’ field is set to receive NULL values.

Hope that helps :D

Does your database table schema allow for you to save a null value? do your validation rules in your model allow for the value to be null? do you get any error/validation error message when you try to save the record?

Thx. for your ideas.

Sometimes it is really easy.

I changed the database and allowed ‘null’ AFTER generating the Model class by using gii.

I used gii and generated the model class again => and everythink is perfect