From: Rafael Kitover Date: Tue, 16 Jun 2009 19:32:22 +0000 (+0000) Subject: Merge 'trunk' into 'on_connect_call' X-Git-Tag: v0.08108~48^2~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fb7a3029bd5b3735ddfad05b301d55a6cd36a1ad;hp=6afe3065c86e7d2eef079450c2bac4f000f1645e;p=dbsrgits%2FDBIx-Class.git Merge 'trunk' into 'on_connect_call' r5525@hlagh (orig r6682): timbunce | 2009-06-15 07:30:21 -0700 Added note that column inflation is not performed r5529@hlagh (orig r6689): timbunce | 2009-06-16 06:06:07 -0700 Removed wording from txn_do that implies the coderef could be executed more than once. r5530@hlagh (orig r6690): timbunce | 2009-06-16 06:14:23 -0700 Added doc note that txn_commit does not perform an actual storage commit unless there's a DBIx::Class transaction currently in effect r5531@hlagh (orig r6691): timbunce | 2009-06-16 06:40:11 -0700 Reverted doc patch r6689 for now, sadly. I'll open a ticket to explain. r5532@hlagh (orig r6693): ribasushi | 2009-06-16 08:22:59 -0700 Fix possible regression with prefetch select resolution --- diff --git a/lib/DBIx/Class/ResultClass/HashRefInflator.pm b/lib/DBIx/Class/ResultClass/HashRefInflator.pm index 45251fa..1b3f2d1 100644 --- a/lib/DBIx/Class/ResultClass/HashRefInflator.pm +++ b/lib/DBIx/Class/ResultClass/HashRefInflator.pm @@ -116,6 +116,12 @@ C<$first> will B be a hashref, it will be a normal CD row since HashRefInflator only affects resultsets at inflation time, and prefetch causes relations to be inflated when the master C<$artist> row is inflated. +=item * + +Column value inflation, e.g., using modules like +L, is not performed. +The returned hash contains the raw database values. + =back =cut diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index fe622b9..ed2d144 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -2599,19 +2599,21 @@ sub _resolved_attrs { my $collapse = $attrs->{collapse} || {}; + if ( my $prefetch = delete $attrs->{prefetch} ) { $prefetch = $self->_merge_attr( {}, $prefetch ); - my @pre_order; - foreach my $p ( ref $prefetch eq 'ARRAY' ? @$prefetch : ($prefetch) ) { - - # bring joins back to level of current class - my $join_map = $self->_joinpath_aliases ($attrs->{from}, $attrs->{seen_join}); - my @prefetch = - $source->_resolve_prefetch( $p, $alias, $join_map, \@pre_order, $collapse ); - push( @{ $attrs->{select} }, map { $_->[0] } @prefetch ); - push( @{ $attrs->{as} }, map { $_->[1] } @prefetch ); - } - push( @{ $attrs->{order_by} }, @pre_order ); + + my $prefetch_ordering = []; + + my $join_map = $self->_joinpath_aliases ($attrs->{from}, $attrs->{seen_join}); + + my @prefetch = + $source->_resolve_prefetch( $prefetch, $alias, $join_map, $prefetch_ordering, $collapse ); + + push( @{ $attrs->{select} }, map { $_->[0] } @prefetch ); + push( @{ $attrs->{as} }, map { $_->[1] } @prefetch ); + + push( @{ $attrs->{order_by} }, @$prefetch_ordering ); } if (delete $attrs->{distinct}) { diff --git a/lib/DBIx/Class/Storage.pm b/lib/DBIx/Class/Storage.pm index a38cf47..bf50762 100644 --- a/lib/DBIx/Class/Storage.pm +++ b/lib/DBIx/Class/Storage.pm @@ -248,6 +248,9 @@ sub txn_begin { die "Virtual method!" } Issues a commit of the current transaction. +It does I perform an actual storage commit unless there's a DBIx::Class +transaction currently in effect (i.e. you called L). + =cut sub txn_commit { die "Virtual method!" } diff --git a/t/prefetch/attrs_untouched.t b/t/prefetch/attrs_untouched.t index 53894b8..41ad883 100644 --- a/t/prefetch/attrs_untouched.t +++ b/t/prefetch/attrs_untouched.t @@ -8,16 +8,7 @@ use Data::Dumper; my $schema = DBICTest->init_schema(); -my $orig_debug = $schema->storage->debug; - -use IO::File; - -BEGIN { - eval "use DBD::SQLite"; - plan $@ - ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 3 ); -} +plan tests => 3; # bug in 0.07000 caused attr (join/prefetch) to be modifed by search # so we check the search & attr arrays are not modified diff --git a/t/prefetch/double_prefetch.t b/t/prefetch/double_prefetch.t new file mode 100644 index 0000000..b666220 --- /dev/null +++ b/t/prefetch/double_prefetch.t @@ -0,0 +1,35 @@ +use warnings; + +use Test::More; +use Test::Exception; +use lib qw(t/lib); +use DBIC::SqlMakerTest; +use DBICTest; + +my $schema = DBICTest->init_schema(); + +plan tests => 1; + +# While this is a rather GIGO case, make sure it behaves as pre-103, +# as it may result in hard-to-track bugs +my $cds = $schema->resultset('Artist') + ->search_related ('cds') + ->search ({}, { + prefetch => [ 'single_track', { single_track => 'cd' } ], + }); + +is_same_sql( + ${$cds->as_query}->[0], + '( + SELECT + cds.cdid, cds.artist, cds.title, cds.year, cds.genreid, cds.single_track, + single_track.trackid, single_track.cd, single_track.position, single_track.title, single_track.last_updated_on, single_track.last_updated_at, + single_track_2.trackid, single_track_2.cd, single_track_2.position, single_track_2.title, single_track_2.last_updated_on, single_track_2.last_updated_at, + cd.cdid, cd.artist, cd.title, cd.year, cd.genreid, cd.single_track + FROM artist me + LEFT JOIN cd cds ON cds.artist = me.artistid + LEFT JOIN track single_track ON single_track.trackid = cds.single_track + LEFT JOIN track single_track_2 ON single_track_2.trackid = cds.single_track + LEFT JOIN cd cd ON cd.cdid = single_track_2.cd + )', +);