From: Christopher H. Laco Date: Tue, 22 May 2007 02:36:28 +0000 (+0000) Subject: %colinfo accessor and inflate_column now work together X-Git-Tag: v0.08010~150^2~55 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=43556c5d5b8734dff2ba5cd4897bd69c4e82bd52;p=dbsrgits%2FDBIx-Class.git %colinfo accessor and inflate_column now work together --- diff --git a/Changes b/Changes index 615e344..cff1189 100644 --- a/Changes +++ b/Changes @@ -12,6 +12,7 @@ Revision history for DBIx::Class class; requires Class::Accessor::Grouped 0.05002+ - added 97result_class.t test, failing ATM - added get_inflated_columns to Row + - %colinfo accessor and inflate_column now work together 0.07006 2007-04-17 23:18:00 - Lots of documentation updates diff --git a/lib/DBIx/Class/InflateColumn.pm b/lib/DBIx/Class/InflateColumn.pm index 721894f..422d8b9 100644 --- a/lib/DBIx/Class/InflateColumn.pm +++ b/lib/DBIx/Class/InflateColumn.pm @@ -73,7 +73,7 @@ sub inflate_column { $self->throw_exception("inflate_column needs attr hashref") unless ref $attrs eq 'HASH'; $self->column_info($col)->{_inflate_info} = $attrs; - $self->mk_group_accessors('inflated_column' => $col); + $self->mk_group_accessors('inflated_column' => [$self->column_info($col)->{accessor} || $col, $col]); return 1; } diff --git a/t/60core.t b/t/60core.t index 75b6ba7..fc1bff2 100644 --- a/t/60core.t +++ b/t/60core.t @@ -7,7 +7,7 @@ use DBICTest; my $schema = DBICTest->init_schema(); -plan tests => 74; +plan tests => 77; # figure out if we've got a version of sqlite that is older than 3.2.6, in # which case COUNT(DISTINCT()) doesn't work @@ -166,6 +166,7 @@ $new = $schema->resultset("Track")->new( { cd => 1, position => 4, title => 'Insert or Update', + last_updated_on => '1973-07-19 12:01:02' } ); $new->update_or_insert; ok($new->in_storage, 'update_or_insert insert ok'); @@ -176,12 +177,15 @@ $new->update_or_insert; is( $schema->resultset("Track")->find(100)->pos, 5, 'update_or_insert update ok'); # get_inflated_columns w/relation and accessor alias +isa_ok($new->updated_date, 'DateTime', 'have inflated object via accessor'); my %tdata = $new->get_inflated_columns; is($tdata{'trackid'}, 100, 'got id'); isa_ok($tdata{'cd'}, 'DBICTest::CD', 'cd is CD object'); is($tdata{'cd'}->id, 1, 'cd object is id 1'); is($tdata{'position'}, 5, 'got position from pos'); is($tdata{'title'}, 'Insert or Update'); +is($tdata{'last_updated_on'}, '1973-07-19T12:01:02'); +isa_ok($tdata{'last_updated_on'}, 'DateTime', 'inflated accessored column'); eval { $schema->class("Track")->load_components('DoesNotExist'); }; diff --git a/t/lib/DBICTest/Schema/Track.pm b/t/lib/DBICTest/Schema/Track.pm index d45e9f2..64eb0ee 100644 --- a/t/lib/DBICTest/Schema/Track.pm +++ b/t/lib/DBICTest/Schema/Track.pm @@ -2,6 +2,7 @@ package # hide from PAUSE DBICTest::Schema::Track; use base 'DBIx::Class::Core'; +__PACKAGE__->load_components(qw/InflateColumn::DateTime/); __PACKAGE__->table('track'); __PACKAGE__->add_columns( @@ -20,6 +21,11 @@ __PACKAGE__->add_columns( data_type => 'varchar', size => 100, }, + last_updated_on => { + data_type => 'datetime', + accessor => 'updated_date', + is_nullable => 1 + }, ); __PACKAGE__->set_primary_key('trackid'); diff --git a/t/lib/sqlite.sql b/t/lib/sqlite.sql index c9de968..5f17ebe 100644 --- a/t/lib/sqlite.sql +++ b/t/lib/sqlite.sql @@ -108,7 +108,8 @@ CREATE TABLE track ( trackid INTEGER PRIMARY KEY NOT NULL, cd integer NOT NULL, position integer NOT NULL, - title varchar(100) NOT NULL + title varchar(100) NOT NULL, + last_updated_on datetime NULL ); --