[html-formfu] Model::DBIC inserts empty strings instead of NULL
values
Peter Shangov
pshangov at yahoo.com
Wed Jun 15 11:08:52 GMT 2011
OK, my oversight.
H::FF::M::DBIC does roughly the following check to determine whether a field's value should be set to NULL:
if ( $is_nullable && $data_type =~ m/^timestamp|date|int|float|numeric/i ) { ... }
I am not sure why the second check is there, but I am sure there is a good reason for it, so I would not change it.
If an option 'null_if_empty' is added for fields, and it forces the field's value to be set to NULL regardless of the data type, would that work for you?
Cheers,
--
Peter
----- Original Message -----
> From: Dmitry Bigunyak <icestar at inbox.ru>
> To: "HTML Form Creation, Rendering and Validation Framework" <html-formfu at lists.scsys.co.uk>
> Cc:
> Sent: Wednesday, 15 June 2011, 12:22
> Subject: Re: [html-formfu] Model::DBIC inserts empty strings instead of NULL values
>
> Hi Peter,
> In my initial post I've written about this option:
>> I thought about using ignore_if_empty option, but I lose ability to
> unset the column value to NULL with it.
>
> thanks for your reply
>
> 15.06.2011 13:12, Peter Shangov пишет:
>> Dmitry, Alex,
>>
>> There is an undocumented option 'ignore_if_empty' for columns,
> which instructs HTML::FormFu::Model::DBIC not to save the value to the database
> if it is an empty string. Can you try that and see if it works? Here is a sample
> configuration:
>>
>> elements:
>> - type: Text
>>
>> name: some_field
>> model_config:
>> ignore_if_empty: 1
>>
>> Cheers,
>>
>> --
>> Peter
>>
>>
>>
>> ----- Original Message -----
>>> From: Alex Povolotsky<tarkhil at over.ru>
>>> To: html-formfu at lists.scsys.co.uk
>>> Cc:
>>> Sent: Monday, 6 June 2011, 12:04
>>> Subject: Re: [html-formfu] Model::DBIC inserts empty strings instead of
> NULL values
>>>
>>> On 04/28/11 17:52, Dmitry Bigunyak wrote:
>>>> Thanks for your reply, I'm not alone :)
>>>> As a temporary solution I've blocked updating on new
> versions. Hope
>>> Carl will reply in that subject.
>>>
>>> I've patched model
>>>
>>> __PACKAGE__->load_components(qw( FilterColumn ));
>>> foreach my $bool ( qw(default_read default_write default_edit) ) {
>>> __PACKAGE__->filter_column($bool => {
>>> filter_to_storage => sub { ($_[1] eq
> '')?undef:$_[1] }
>>> });
>>> }
>>>
>>>
>>> It's ugly as hell, but it works fine and replace empty string with
> undef.
>>>
>>> Alex
>>>
>>> _______________________________________________
>>> HTML-FormFu mailing list
>>> HTML-FormFu at lists.scsys.co.uk
>>> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>>>
>> _______________________________________________
>> HTML-FormFu mailing list
>> HTML-FormFu at lists.scsys.co.uk
>> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>>
>>
>
> --
> Dmitry Bigunyak
> e-mail: icestar at inbox.ru
>
>
> _______________________________________________
> HTML-FormFu mailing list
> HTML-FormFu at lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>
More information about the HTML-FormFu
mailing list