Re: What is the 'right' way to solve this postgres problem?
Thanks Villas, that sounds like very good advice. I can already think of lots of situations where a Yes/No question might need to be expanded. As for CakePHP... I've decided not to bother with it. I think there's just too much going on behind the scenes that will at best slow my application down, and at worst, break it in strange and wonderful ways. Messing up my NULL values is just the start. I'm gonna stick with my own lightweight framework. :-( On 7 Apr, 10:52, villas wrote: > Hi Dan > > If you are not already having to handle a legacy DB, why not go with > your idea of Char(1)? > > I use Char(1) all the time in preference to Boolean. My experience > has repeatedly shown that I start off with a requirement for T and F > but then need to expand the possibilities. > > Only last week I changed my Agents table from ActiveStatus = Y,N to: > ActiveStatus = (W)eekly update, (M)onthly update, (Y) Active-without > updates, (N) Inactive. > > As my table had ActiveStatus as Char(1), it was a breeze. It saved > me having to introduce a new field for UpdateFrequency. > > Of course the above may not have been the 'right' way for everyone, > but it was definitely more convenient for me! > > Best wishes. > > On Apr 6, 6:08 pm, "cheeser...@googlemail.com" > > > > wrote: > > Thanks for the suggestion. I see what you mean. It might allow me to > > correctly save NULL data, but I think I'm still gonna need a way to > > correctly retrieve the NULLs from the database too. Also, I'm > > concerned that I'd then have to set the fieldlist manually every time > > I call save(), which sounds like a disaster. I need the save method > > to just work. > > > On 6 Apr, 16:52, brian wrote: > > > > I'm not sure this will work (or if it's the best way) but have a lok > > > at the 3rd param for Model::save, $fieldList. I suppose you could > > > create an array from the return of schema() (using just the main keys, > > > I mean) and unset those fields that were not answered by the user and > > > pass that to save(). > > > > On Mon, Apr 6, 2009 at 9:43 AM, cheeser...@googlemail.com > > > > wrote: > > > > > Hi Everyone, > > > > > I'm excited to be embarking on my first project using CakePHP, but > > > > unfortunately after only 1 afternoon, I seem to have hit a real > > > > problem. > > > > > I have several boolean fields in my postgres table which can also take > > > > a null value. This is because I want to make a distinction between a > > > > user replying 'no' to a question, or just declining to answer it. > > > > However, the database layer seems to be automatically converting the > > > > NULL values to PHP false values. > > > > > I guess this is because CakePHP sees that the field is of type > > > > 'boolean' and so casts it to a PHP boolean type. > > > > > I really need this functionality, so I'm considering a few options, > > > > but I want to try and do this 'right' and stick to the convention over > > > > configuration and MVC philosophies that Cake is built around. What do > > > > you think is the best approach? > > > > > Override functions in the database abstraction layer to make sure NULL > > > > values are preserved (although I'm scared this will be difficult and > > > > break other stuff). > > > > > Create a new postgres data type to handle these 'tertiary' values... > > > > perhaps a char(1) with the domain restricted to Y,N or X (for null). > > > > > Set the type to char(1) and build some logic into the controller to > > > > ensure that only Y,N,X get inserted Could have X as the default > > > > value in the database... > > > > > Or some other approach. I have no idea. Please help! Cheers, Dan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: What is the 'right' way to solve this postgres problem?
Thanks for the suggestion. I see what you mean. It might allow me to correctly save NULL data, but I think I'm still gonna need a way to correctly retrieve the NULLs from the database too. Also, I'm concerned that I'd then have to set the fieldlist manually every time I call save(), which sounds like a disaster. I need the save method to just work. On 6 Apr, 16:52, brian wrote: > I'm not sure this will work (or if it's the best way) but have a lok > at the 3rd param for Model::save, $fieldList. I suppose you could > create an array from the return of schema() (using just the main keys, > I mean) and unset those fields that were not answered by the user and > pass that to save(). > > On Mon, Apr 6, 2009 at 9:43 AM, cheeser...@googlemail.com > > > > wrote: > > > Hi Everyone, > > > I'm excited to be embarking on my first project using CakePHP, but > > unfortunately after only 1 afternoon, I seem to have hit a real > > problem. > > > I have several boolean fields in my postgres table which can also take > > a null value. This is because I want to make a distinction between a > > user replying 'no' to a question, or just declining to answer it. > > However, the database layer seems to be automatically converting the > > NULL values to PHP false values. > > > I guess this is because CakePHP sees that the field is of type > > 'boolean' and so casts it to a PHP boolean type. > > > I really need this functionality, so I'm considering a few options, > > but I want to try and do this 'right' and stick to the convention over > > configuration and MVC philosophies that Cake is built around. What do > > you think is the best approach? > > > Override functions in the database abstraction layer to make sure NULL > > values are preserved (although I'm scared this will be difficult and > > break other stuff). > > > Create a new postgres data type to handle these 'tertiary' values... > > perhaps a char(1) with the domain restricted to Y,N or X (for null). > > > Set the type to char(1) and build some logic into the controller to > > ensure that only Y,N,X get inserted Could have X as the default > > value in the database... > > > Or some other approach. I have no idea. Please help! Cheers, Dan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
What is the 'right' way to solve this postgres problem?
Hi Everyone, I'm excited to be embarking on my first project using CakePHP, but unfortunately after only 1 afternoon, I seem to have hit a real problem. I have several boolean fields in my postgres table which can also take a null value. This is because I want to make a distinction between a user replying 'no' to a question, or just declining to answer it. However, the database layer seems to be automatically converting the NULL values to PHP false values. I guess this is because CakePHP sees that the field is of type 'boolean' and so casts it to a PHP boolean type. I really need this functionality, so I'm considering a few options, but I want to try and do this 'right' and stick to the convention over configuration and MVC philosophies that Cake is built around. What do you think is the best approach? Override functions in the database abstraction layer to make sure NULL values are preserved (although I'm scared this will be difficult and break other stuff). Create a new postgres data type to handle these 'tertiary' values... perhaps a char(1) with the domain restricted to Y,N or X (for null). Set the type to char(1) and build some logic into the controller to ensure that only Y,N,X get inserted Could have X as the default value in the database... Or some other approach. I have no idea. Please help! Cheers, Dan --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---