Handling Checkbox Where Schema Uses Bit Datatype (Mysql)

Hi,

It couldn’t be simpler and I can’t believe I haven’t found a solution to this yet:

  • DB schema defines checkboxes as bit(1) NOT NULL DEFAULT b’0’, as MySQL recommends for boolean fields (terms and conditions acceptance, etc).
  • Code in view file is:



<?php echo $form->labelEx($profile, 'terms_accepted'); ?>

<?php echo $form->checkBox($profile, 'terms_accepted'); ?>

<?php echo $form->error($profile, 'terms_accepted'); ?>



Problem: in ‘update’ use case, the boolean attributes which have b(‘1’) in the DB are not marked as checked in the view.

I thought there was an issue in Yii that was fixed in v1.1.14 (as noted here) but after upgrading to v1.1.14 this still doesn’t work.

I guess I must be doing something wrong as there’s little evidence of similar complaints on the web.

Maybe this would help as well (I don’t think so): in the model rules() method I have:





 array(

  'terms_accepted',

  'in',

  'range' => array('1')

),



How do I get checkboxes represented in the MySQL DB as BIT(1) to work in all use cases in Yii?..

Thanks.