[Dbix-class] Pointless update on a date field

Pedro Melo melo at simplicidade.org
Thu Sep 13 18:06:29 GMT 2007


Hi,

On Sep 13, 2007, at 4:47 PM, Richard Jones wrote:

> Matt S Trout wrote:
>>> Result of 2 updates where only a non-date field should have been  
>>> affected:
>>>
>>> PRE: 1934-12-21
>>> POST:1934-12-21
>> That one looks like it shouldn't have updated.
>>
>>> PRE: 1927-09-09
>>> POST:1927-9-9
>> That one looks like what I was expecting.
>> You should just be dealing in DateTime objects and using the DBIC  
>> accessors;
>> the inflate/deflate will be transparent.
>> If you're using your own code to transform dates to/from mysql  
>> format you're
>> doing it wrong and any bugs are your problem.
>
> Yes I know - my own code was just to get me going so I could  
> retrieve stuff from the db when the user inputs dates in any EU  
> format (I use Date::Calc::Decode_Date_EU to extract the year/month/ 
> day info). I knew I would have to revisit InflateColumn at some stage.
>
> I have setup the table class as shown in  
> DBIC::InflateColumn::DateTime, ie:
> __PACKAGE__->add_columns( dob => { date_type=> 'date' } ),

Not 'date_type', 'data_type'.


> but not:
> __PACKAGE__->inflate_column( dob => {
>   inflate => sub { ... },
>   deflate => sub { ... }
> } ) as described in DBIx::Class::InflateColumn.

err.. you must be looking at an old version: http://search.cpan.org/ 
perldoc?DBIx::Class::InflateColumn::DateTime

There is no inflate/deflate there...

After you follow the instructions in the URL above, this will work:

my $row = $schema->resultset('YourSourceName')->create({ dob =>  
DateTime->now });

so will this:

$row->dob(DateTime->now);

and

ok($row->dob->isa('DateTime'), 'you got a datetime there...');

will be your friend.

Best regards,
-- 
Pedro Melo
Blog: http://www.simplicidade.org/notes/
XMPP ID: melo at simplicidade.org
Use XMPP!





More information about the DBIx-Class mailing list