From: Peter Rabbitson Date: Wed, 29 Apr 2009 08:22:16 +0000 (+0000) Subject: test and patch for failing mini-prefetch via columns (arcanez++) X-Git-Tag: v0.08102~12 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=faf7900350fc51574f6c1b28942aee23b8c03213;p=dbsrgits%2FDBIx-Class.git test and patch for failing mini-prefetch via columns (arcanez++) --- diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index fe5a9aa..c6fd923 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -1029,7 +1029,6 @@ sub inflate_result { $fetched = $pre_source->result_class->inflate_result( $pre_source, @{$pre_val}); } - $new->related_resultset($pre)->set_cache([ $fetched ]); my $accessor = $source->relationship_info($pre)->{attrs}{accessor}; $class->throw_exception("No accessor for prefetched $pre") unless defined $accessor; @@ -1040,6 +1039,7 @@ sub inflate_result { } else { $class->throw_exception("Prefetch not supported with accessor '$accessor'"); } + $new->related_resultset($pre)->set_cache([ $fetched ]); } } return $new; diff --git a/t/76select.t b/t/76select.t index 77b5541..74405a3 100644 --- a/t/76select.t +++ b/t/76select.t @@ -5,10 +5,11 @@ use Test::More; use Test::Exception; use lib qw(t/lib); use DBICTest; +use DBIC::SqlMakerTest; my $schema = DBICTest->init_schema(); -plan tests => 13; +plan tests => 19; my $rs = $schema->resultset('CD')->search({}, { @@ -74,9 +75,55 @@ is ($subsel->next->title, $cds->next->title, 'Second CD title match'); is($schema->resultset('CD')->current_source_alias, "me", '$rs->current_source_alias returns "me"'); -my @cds = $schema->resultset('CD')->search({}, + + +$rs = $schema->resultset('CD')->search({}, { 'join' => 'artist', - 'columns' => ['cdid','title','artist.name'], + 'columns' => ['cdid', 'title', 'artist.name'], } ); + +my @query = @${$rs->as_query}; + +is_same_sql_bind ( + @query, + [], + '(SELECT me.cdid, me.title, artist.name FROM cd me JOIN artist artist ON artist.artistid = me.artist)', + [], + 'Use of columns attribute results in proper sql' +); + +lives_ok(sub { + $rs->first->get_column('cdid') +}, 'columns 1st rscolumn present'); + +lives_ok(sub { + $rs->first->get_column('title') +}, 'columns 2nd rscolumn present'); + + +$rs = $schema->resultset('CD')->search({}, + { + 'join' => 'artist', + '+columns' => ['cdid', 'title', 'artist.name'], + } +); + +@query = @${$rs->as_query}; + +is_same_sql_bind ( + @query, + [], + '(SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track, me.cdid, me.title, artist.name FROM cd me JOIN artist artist ON artist.artistid = me.artist)', + [], + 'Use of columns attribute results in proper sql' +); + +lives_ok(sub { + $rs->first->get_column('cdid') +}, 'columns 1st rscolumn present'); + +lives_ok(sub { + $rs->first->get_column('title') +}, 'columns 2nd rscolumn present');