From: Moritz Onken Date: Sat, 13 Mar 2010 12:09:59 +0000 (+0000) Subject: call inflate_result on new_result, but not from the CDBI compat layer X-Git-Tag: v0.08121~65 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=de621449d983d7dbc139687a1d9f157524009942;p=dbsrgits%2FDBIx-Class.git call inflate_result on new_result, but not from the CDBI compat layer --- diff --git a/lib/DBIx/Class/CDBICompat/LiveObjectIndex.pm b/lib/DBIx/Class/CDBICompat/LiveObjectIndex.pm index f05eff7..d62e325 100644 --- a/lib/DBIx/Class/CDBICompat/LiveObjectIndex.pm +++ b/lib/DBIx/Class/CDBICompat/LiveObjectIndex.pm @@ -73,8 +73,11 @@ sub insert { sub inflate_result { my ($class, @rest) = @_; + + # we don't want to inflate_result on new_result + return $rest[3] if(defined $rest[3] && Scalar::Util::blessed $rest[3]); + my $new = $class->next::method(@rest); - return $new if $new->nocache; if (my $key = $new->ID) { diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 4247459..cbe81d3 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1859,8 +1859,9 @@ sub new_result { -source_handle => $self->_source_handle, -result_source => $self->result_source, # DO NOT REMOVE THIS, REQUIRED ); - - return $self->result_class->new(\%new); + my $row = $self->result_class->new(\%new); + #return $row; + return $self->result_class->inflate_result($self->result_source, $row->{_column_data}, undef, $row); } # _merge_cond_with_data diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index 2777114..1d3a7c6 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -1067,7 +1067,7 @@ sub store_column { =over -=item Arguments: $result_source, \%columndata, \%prefetcheddata +=item Arguments: $result_source, \%columndata, \%prefetcheddata, [$row] =item Returns: A Row object @@ -1088,8 +1088,9 @@ L, see L. =cut sub inflate_result { - my ($class, $source, $me, $prefetch) = @_; - + my ($class, $source, $me, $prefetch, $row) = @_; + return $row if (defined $row && (Scalar::Util::blessed $row)); + my ($source_handle) = $source; if ($source->isa('DBIx::Class::ResultSourceHandle')) { diff --git a/t/93single_accessor_object.t b/t/93single_accessor_object.t index 892e656..987b185 100644 --- a/t/93single_accessor_object.t +++ b/t/93single_accessor_object.t @@ -45,20 +45,20 @@ plan tests => 10; $schema = DBICTest->init_schema(); { - my $artist = $schema->resultset('Artist')->create({ artistid => 666, name => 'bad religion' }); - my $cd = $schema->resultset('CD')->create({ cdid => 187, artist => 1, title => 'how could hell be any worse?', year => 1982, genreid => undef }); + my $artist = $schema->resultset('Artist')->create({ artistid => 666, name => 'bad religion' }); + my $cd = $schema->resultset('CD')->create({ cdid => 187, artist => 1, title => 'how could hell be any worse?', year => 1982, genreid => undef }); - ok(!defined($cd->get_column('genreid')), 'genreid is NULL'); #no accessor was defined for this column - ok(!defined($cd->genre), 'genre accessor returns undef'); + ok(!defined($cd->get_column('genreid')), 'genreid is NULL'); #no accessor was defined for this column + ok(!defined($cd->genre), 'genre accessor returns undef'); } $schema = DBICTest->init_schema(); { - my $artist = $schema->resultset('Artist')->create({ artistid => 666, name => 'bad religion' }); - my $genre = $schema->resultset('Genre')->create({ genreid => 88, name => 'disco' }); - my $cd = $schema->resultset('CD')->create({ cdid => 187, artist => 1, title => 'how could hell be any worse?', year => 1982 }); + my $artist = $schema->resultset('Artist')->create({ artistid => 666, name => 'bad religion' }); + my $genre = $schema->resultset('Genre')->create({ genreid => 88, name => 'disco' }); + my $cd = $schema->resultset('CD')->create({ cdid => 187, artist => 1, title => 'how could hell be any worse?', year => 1982 }); - dies_ok { $cd->genre } 'genre accessor throws without column'; + dies_ok { $cd->genre } 'genre accessor throws without column'; } diff --git a/t/row/inflate_result.t b/t/row/inflate_result.t index c31d804..370c205 100644 --- a/t/row/inflate_result.t +++ b/t/row/inflate_result.t @@ -2,6 +2,7 @@ package My::Schema::Result::User; use strict; use warnings; +use DBIx::Class::ResultClass::HashRefInflator; use base qw/DBIx::Class::Core/; ### Define what our admin class is, for ensure_class_loaded() @@ -20,6 +21,7 @@ __PACKAGE__->set_primary_key('user_id'); sub inflate_result { my $self = shift; my $ret = $self->next::method(@_); + if ( $ret->admin ) { ### If this is an admin, rebless for extra functions $self->ensure_class_loaded($admin_class); bless $ret, $admin_class; @@ -61,6 +63,7 @@ package main; use lib qw(t/lib); use DBICTest; +use DBIx::Class::ResultClass::HashRefInflator; use Test::More; @@ -84,10 +87,12 @@ ok( ) ); +my $rs = $schema->resultset('User'); + TODO: { local $TODO = 'New objects should also be inflated'; - my $user = $schema->resultset('User')->create($user_data); - my $admin = $schema->resultset('User')->create($admin_data); + my $user = $rs->create($user_data); + my $admin = $rs->create($admin_data); is( ref $user, 'My::Schema::Result::User' ); is( ref $admin, 'My::Schema::Result::User::Admin' );