Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...?
  • Loading branch information...
commit 9ae300a43ff4db9bf5084a009cce726c694f3612 1 parent 41a5d67
Peter Rabbitson ribasushi authored
4 Changes
... ... @@ -1,5 +1,9 @@
1 1 Revision history for DBIx::Class
2 2
  3 + * Fixes
  4 + - Fix another embarrassing regression preventing correct refining of
  5 + the search criteria on a prefetched relation (broken in 0.08205)
  6 +
3 7 0.08208 2013-02-20 09:56 (UTC)
4 8 * New Features / Changes
5 9 - A bunch of nonsensically named arguments to the SQL::Translator
6 lib/DBIx/Class/ResultSet.pm
@@ -389,11 +389,11 @@ sub search_rs {
389 389 my $cache;
390 390 my %safe = (alias => 1, cache => 1);
391 391 if ( ! List::Util::first { !$safe{$_} } keys %$call_attrs and (
392   - ! defined $_[0]
  392 + ! defined $call_cond
393 393 or
394   - ref $_[0] eq 'HASH' && ! keys %{$_[0]}
  394 + ref $call_cond eq 'HASH' && ! keys %$call_cond
395 395 or
396   - ref $_[0] eq 'ARRAY' && ! @{$_[0]}
  396 + ref $call_cond eq 'ARRAY' && ! @$call_cond
397 397 )) {
398 398 $cache = $self->get_cache;
399 399 }
56 t/prefetch/refined_search_on_relation.t
... ... @@ -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 comments on commit 9ae300a

Please sign in to comment.
Something went wrong with that request. Please try again.