Skip to content

Commit 9ae300a

Browse files
committed
Fix regression breaking search on prefetched rel (broken by 5e2a051)
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...?
1 parent 41a5d67 commit 9ae300a

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

Changes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Revision history for DBIx::Class
22

3+
* Fixes
4+
- Fix another embarrassing regression preventing correct refining of
5+
the search criteria on a prefetched relation (broken in 0.08205)
6+
37
0.08208 2013-02-20 09:56 (UTC)
48
* New Features / Changes
59
- A bunch of nonsensically named arguments to the SQL::Translator

lib/DBIx/Class/ResultSet.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,11 @@ sub search_rs {
389389
my $cache;
390390
my %safe = (alias => 1, cache => 1);
391391
if ( ! List::Util::first { !$safe{$_} } keys %$call_attrs and (
392-
! defined $_[0]
392+
! defined $call_cond
393393
or
394-
ref $_[0] eq 'HASH' && ! keys %{$_[0]}
394+
ref $call_cond eq 'HASH' && ! keys %$call_cond
395395
or
396-
ref $_[0] eq 'ARRAY' && ! @{$_[0]}
396+
ref $call_cond eq 'ARRAY' && ! @$call_cond
397397
)) {
398398
$cache = $self->get_cache;
399399
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
use strict;
2+
use warnings;
3+
4+
use Test::More;
5+
use lib qw(t/lib);
6+
use DBICTest;
7+
8+
my $schema = DBICTest->init_schema();
9+
10+
my $art = $schema->resultset('Artist')->find(
11+
{ 'me.artistid' => 1 },
12+
{ prefetch => 'cds', order_by => { -desc => 'cds.year' } }
13+
);
14+
15+
is (
16+
$art->cds->search({ year => 1999 })->next->year,
17+
1999,
18+
'Found expected CD with year 1999 after refined search',
19+
);
20+
21+
is (
22+
$art->cds->count({ year => 1999 }),
23+
1,
24+
'Correct refined count',
25+
);
26+
27+
# this still should emit no queries:
28+
{
29+
my $queries = 0;
30+
my $orig_debug = $schema->storage->debug;
31+
$schema->storage->debugcb(sub { $queries++; });
32+
$schema->storage->debug(1);
33+
34+
my $cds = $art->cds;
35+
is (
36+
$cds->count,
37+
3,
38+
'Correct prefetched count',
39+
);
40+
41+
my @years = qw(2001 1999 1997);
42+
while (my $cd = $cds->next) {
43+
is (
44+
$cd->year,
45+
(shift @years),
46+
'Correct prefetched cd year',
47+
);
48+
}
49+
50+
$schema->storage->debug($orig_debug);
51+
$schema->storage->debugcb(undef);
52+
53+
is ($queries, 0, 'No queries on prefetched operations');
54+
}
55+
56+
done_testing;

0 commit comments

Comments
 (0)