starts_when => { data_type => 'varchar', inflate_date => 1 }
);
+It's also possible to explicitly skip inflation:
+
+ __PACKAGE__->add_columns(
+ starts_when => { data_type => 'datetime', inflate_datetime => 0 }
+ );
+
=head1 DESCRIPTION
This module figures out the type of DateTime::Format::* class to
return unless defined($info->{data_type});
my $type = lc($info->{data_type});
$type = 'datetime' if ($type =~ /^timestamp/);
- $type = 'datetime' if exists $info->{inflate_datetime} and $info->{inflate_datetime};
- $type = 'date' if exists $info->{inflate_date} and $info->{inflate_date};
+ $type = 'datetime' if $info->{inflate_datetime};
+ $type = 'date' if $info->{inflate_date};
my $timezone;
if ( exists $info->{extra} and exists $info->{extra}{timezone} and defined $info->{extra}{timezone} ) {
$timezone = $info->{extra}{timezone};
my $undef_if_invalid = $info->{datetime_undef_if_invalid};
- if ($type eq 'datetime' || $type eq 'date') {
+ my $do_inflate = 1;
+ $do_inflate = 0 if exists $info->{inflate_datetime} and $info->{inflate_datetime} == 0;
+ $do_inflate = 0 if exists $info->{inflate_date} and $info->{inflate_date} == 0;
+
+ if ($do_inflate and ($type eq 'datetime' || $type eq 'date')) {
my ($parse, $format) = ("parse_${type}", "format_${type}");
$self->inflate_column(
$column =>
eval { require DateTime::Format::MySQL };
plan skip_all => "Need DateTime::Format::MySQL for inflation tests" if $@;
-plan tests => 25;
+plan tests => 27;
# inflation test
my $event = $schema->resultset("Event")->find(1);
isa_ok($event->varchar_date, 'DateTime', 'DateTime returned');
isa_ok($event->varchar_datetime, 'DateTime', 'DateTime returned');
+## skip inflation field
+isnt(ref($event->skip_inflation), 'DateTime', 'No DateTime returned for skip inflation column');
+
# klunky, but makes older Test::More installs happy
my $createo = $event->created_on;
is("$createo", '2006-06-22T21:00:05', 'Correct date/time');
## varchar field using inflate_datetime => 1
my $varchar_datetime = $event->varchar_datetime;
is("$varchar_datetime", '2006-05-22T19:05:07', 'Correct date/time');
+
+## skip inflation field
+my $skip_inflation = $event->skip_inflation;
+is ("$skip_inflation", '2006-04-21 18:04:06', 'Correct date/time');
]);
$schema->populate('Event', [
- [ qw/id starts_at created_on varchar_date varchar_datetime/ ],
- [ 1, '2006-04-25 22:24:33', '2006-06-22 21:00:05', '2006-07-23', '2006-05-22 19:05:07'],
+ [ qw/id starts_at created_on varchar_date varchar_datetime skip_inflation/ ],
+ [ 1, '2006-04-25 22:24:33', '2006-06-22 21:00:05', '2006-07-23', '2006-05-22 19:05:07', '2006-04-21 18:04:06'],
]);
$schema->populate('Link', [
created_on => { data_type => 'timestamp' },
varchar_date => { data_type => 'varchar', inflate_date => 1, size => 20, is_nullable => 1 },
varchar_datetime => { data_type => 'varchar', inflate_datetime => 1, size => 20, is_nullable => 1 },
+ skip_inflation => { data_type => 'datetime', inflate_datetime => 0, size => 20, is_nullable => 1 },
);
__PACKAGE__->set_primary_key('id');
--
-- Created by SQL::Translator::Producer::SQLite
--- Created on Fri Oct 24 21:02:41 2008
+-- Created on Fri Oct 24 21:31:55 2008
--
BEGIN TRANSACTION;
starts_at datetime NOT NULL,
created_on timestamp NOT NULL,
varchar_date varchar(20),
- varchar_datetime varchar(20)
+ varchar_datetime varchar(20),
+ skip_inflation datetime(20)
);