From: Peter Rabbitson Date: Sat, 23 Feb 2013 14:17:47 +0000 (+0100) Subject: Fix regression breaking search on prefetched rel (broken by 5e2a0518) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9ae300a43ff4db9bf5084a009cce726c694f3612;p=dbsrgits%2FDBIx-Class-Historic.git Fix regression breaking search on prefetched rel (broken by 5e2a0518) Boy 0.08205 was a bad release, so much crap went in undetected by any of our tests :( Maybe it's time for Devel::Cover...? --- diff --git a/Changes b/Changes index e5841ac..5283890 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ Revision history for DBIx::Class + * Fixes + - Fix another embarrassing regression preventing correct refining of + the search criteria on a prefetched relation (broken in 0.08205) + 0.08208 2013-02-20 09:56 (UTC) * New Features / Changes - A bunch of nonsensically named arguments to the SQL::Translator diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 10905b2..b5397b6 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -389,11 +389,11 @@ sub search_rs { my $cache; my %safe = (alias => 1, cache => 1); if ( ! List::Util::first { !$safe{$_} } keys %$call_attrs and ( - ! defined $_[0] + ! defined $call_cond or - ref $_[0] eq 'HASH' && ! keys %{$_[0]} + ref $call_cond eq 'HASH' && ! keys %$call_cond or - ref $_[0] eq 'ARRAY' && ! @{$_[0]} + ref $call_cond eq 'ARRAY' && ! @$call_cond )) { $cache = $self->get_cache; } diff --git a/t/prefetch/refined_search_on_relation.t b/t/prefetch/refined_search_on_relation.t new file mode 100644 index 0000000..8a7035c --- /dev/null +++ b/t/prefetch/refined_search_on_relation.t @@ -0,0 +1,56 @@ +use strict; +use warnings; + +use Test::More; +use lib qw(t/lib); +use DBICTest; + +my $schema = DBICTest->init_schema(); + +my $art = $schema->resultset('Artist')->find( + { 'me.artistid' => 1 }, + { prefetch => 'cds', order_by => { -desc => 'cds.year' } } +); + +is ( + $art->cds->search({ year => 1999 })->next->year, + 1999, + 'Found expected CD with year 1999 after refined search', +); + +is ( + $art->cds->count({ year => 1999 }), + 1, + 'Correct refined count', +); + +# this still should emit no queries: +{ + my $queries = 0; + my $orig_debug = $schema->storage->debug; + $schema->storage->debugcb(sub { $queries++; }); + $schema->storage->debug(1); + + my $cds = $art->cds; + is ( + $cds->count, + 3, + 'Correct prefetched count', + ); + + my @years = qw(2001 1999 1997); + while (my $cd = $cds->next) { + is ( + $cd->year, + (shift @years), + 'Correct prefetched cd year', + ); + } + + $schema->storage->debug($orig_debug); + $schema->storage->debugcb(undef); + + is ($queries, 0, 'No queries on prefetched operations'); +} + +done_testing;