Hi Drake,

You should not use a NULL as a meaningfull value (NULL is exactly - no
value). If you want your questions to reflect the possibilities of:
1) Not answered.
2) A Yes answer;
3) A No answer;
you should design your column accordingly - to be able to hold three
values (0 - not answered, 1 - No, 2 - Yes)
Enjoy,
   John

On May 13, 12:53 am, Drake <[email protected]> wrote:
> I'm developing my first CakePHP and this is my first post here, so
> bare with me. Thanks in advance for any help.
>
> I have a form with several yes/no questions. I chose to store these in
> the database as tinyint(1) (using mysql), since they are fundamentally
> boolean values. By default, CakePHP renders these fields as
> checkboxes. I chose to override this functionality and display these
> questions with two yes/no radio buttons, so "no" and "nothing
> selected" can be distinguished. This setup is working great if one of
> the two options is selected.
>
> I'm having problems getting Cake to do the right thing, however, when
> neither radio button is selected. In this case, I would like to store
> NULL in the database, to represent the fact that neither option was
> selected. After posting, $this->data correctly shows empty values for
> the fields with neither option selected. But Cake is automatically
> writing "0" to all the tinyint fields that aren't explicitly set to
> "1". This includes all the fields with no option selected.
>
> OK, so my question is, is there any way to stop cake from writing "0"
> to a tinyint field by default, if no value is set in $this->data?
>
> If this isn't possible, I think I can probably change all these
> tinyint fields into enums with "yes" and "no" as options, or something
> along those lines. If possible, though, I'd like to stick to tinyints
> since they're more appropriate for the data.
>
> Thanks for the help!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to