From: Nigel Metheringham Date: Sun, 26 Nov 2006 19:24:39 +0000 (+0000) Subject: Merge 'trunk' into 'DBIx-Class-current' X-Git-Tag: v0.08010~150^2~122 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9d2d06079ecf52dd3cc0984cb677e7be75e86e7b;hp=8795fefb31085d0e9d88c6d6dcf1d7a83e1d417a;p=dbsrgits%2FDBIx-Class.git Merge 'trunk' into 'DBIx-Class-current' r34145@cain (orig r2943): nigel | 2006-11-26 13:24:39 +0000 Added a test to check that the result from a 2 level has_many prefetch is the same as that got by expanding the relationships one thing at a time. --- diff --git a/t/76joins.t b/t/76joins.t index 1033b53..9401502 100644 --- a/t/76joins.t +++ b/t/76joins.t @@ -16,7 +16,7 @@ BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 49 ); + : ( tests => 50 ); } # figure out if we've got a version of sqlite that is older than 3.2.6, in @@ -343,3 +343,44 @@ like( $sql, qr/^SELECT tracks_2\.trackid/, "join not collapsed for search_relate $schema->storage->debug($orig_debug); $schema->storage->debugobj->callback(undef); + +# ------------- +# +# Tests for multilevel has_many prefetch + +# artist resultsets - with and without prefetch +my $art_rs = $schema->resultset('Artist'); +my $art_rs_pr = $art_rs->search( + {}, + { + join => [ { cds => ['tracks'] } ], + prefetch => [ { cds => ['tracks'] } ] + } +); + +# This test does the same operation twice - once on a +# set of items fetched from the db with no prefetch of has_many rels +# The second prefetches 2 levels of has_many +# We check things are the same by comparing the name or title +# we build everything into a hash structure and compare the one +# from each rs to see what differs + +sub make_hash_struc { + my $rs = shift; + + my $struc = {}; + foreach my $art ( $rs->all ) { + foreach my $cd ( $art->cds ) { + foreach my $track ( $cd->tracks ) { + $struc->{ $art->name }{ $cd->title }{ $track->title }++; + } + } + } + return $struc; +} + +my $prefetch_result = make_hash_struc($art_rs_pr); +my $nonpre_result = make_hash_struc($art_rs); + +is_deeply( $prefetch_result, $nonpre_result, + 'Compare 2 level prefetch result to non-prefetch result' );