Error Of Casting Type With Boolean Set To False And Postgresql


first I would like to prevent that I’m aware of the problem of casting boolean variable when setting to false but I resolve this problem explain in for model and form in general. But here I face to a different situation and I don’t find any answer yet. I rely on you to help me =P

Let’s take an example : I have one model with two fields field A and field B. They are both boolean.

For each field I create a different form Form A allows to set A and form B … B.

I create then different action and scenario in order to set rules like ‘A is unsafe if we’re in scenario B’ and ‘B unsafe if we’re in scenario A’ in order to doesn’t change the other parameter which is not in form.

However when I apply an edition of the record, for A for example, I have an exception because B, as it’s false, is set to void, and postgresql doesn’t take void boolean…

(no Problem if before B has been set to true)

CDbCommand failed to execute the SQL statement: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type boolean: "".

May you help me ?

You can use the beforeSave() method (or beforeValidate()) of your AR-model:

    public function beforeSave()


        if (parent::beforeSave()) 



             $this->booleanField = false; //or 0 ... whatever the db wants



           return true; //important to return true



Thanks for your reply, but as I have a lot of boolean field in all of my controller, I don’t really want to list them all. I found an alternative, using the yii changes describe in topic give in my main post. I use the same form for A and B except that for form A, I set B field hidden, and in form B, I set A field hidden. Thanks to that, the hidden field is well set again by the good attribute. And no need to set it in unsafe mode.