model->save() doesn't error like I'd expect it to

$user = new User();


$errors = $user->getErrors();// has data, $user->name can't be null

I’ve got some save code (more complicated than above) that is generating an error. If I don’t want it to be suppressed any way that I can have it automatically throw the correct CDbException, or how do I turn the getErrors call into a CDbException?

Hi Woil,

Just a suggestion for your consideration - Why would you want to save “empty” data? Maybe you can set some error checking at the MVC’s View. Only if the form is correctly fill-up will then save into the database.

Do correct me if I have misinterpret your question.

Hope it help.

I wasn’t really saving empty information, just giving a summary.

Really I was doing something like:

new User()

set a bunch of properties


One of the columns on User was set as Not NULL in the database (mysql) but instead of throwing an exception it doesn’t insert into the db and puts the error in the getErrors() call.

It seems like you declared a validation rule for the column in question.

You may want to do like this:

  1. call validate() and check return value

2a. if false take appropriate action

2b. if true call save(false)