From: Peter Rabbitson Date: Thu, 28 May 2009 11:02:22 +0000 (+0000) Subject: Fix multiprefetch warning - we can now count properly X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2e2512552309024151dc45c24b66032f510ca613;p=dbsrgits%2FDBIx-Class-Historic.git Fix multiprefetch warning - we can now count properly --- diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index c657c3a..cd819a8 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -1274,8 +1274,7 @@ sub resolve_prefetch { ? "at the same level (${as_prefix}) " : "at top level " ) - . 'will currently disrupt both the functionality of $rs->count(), ' - . 'and the amount of objects retrievable via $rs->next(). ' + . 'will explode the number of row objects retrievable via ->next or ->all. ' . 'Use at your own risk.' ); } @@ -1360,8 +1359,7 @@ sub _resolve_prefetch { ? "at the same level (${as_prefix}) " : "at top level " ) - . 'will currently disrupt both the functionality of $rs->count(), ' - . 'and the amount of objects retrievable via $rs->next(). ' + . 'will explode the number of row objects retrievable via ->next or ->all. ' . 'Use at your own risk.' ); } diff --git a/t/prefetch/multiple_hasmany.t b/t/prefetch/multiple_hasmany.t index 7fc93812..96d86c5 100644 --- a/t/prefetch/multiple_hasmany.t +++ b/t/prefetch/multiple_hasmany.t @@ -7,19 +7,12 @@ use lib qw(t/lib); use DBICTest; use Data::Dumper; -my $schema = DBICTest->init_schema(); +plan tests => 10; -my $orig_debug = $schema->storage->debug; +my $schema = DBICTest->init_schema(); use IO::File; -BEGIN { - eval "use DBD::SQLite"; - plan $@ - ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 16 ); -} - # once the following TODO is complete, remove the 2 warning tests immediately # after the TODO block # (the TODO block itself contains tests ensuring that the warns are removed) @@ -97,24 +90,21 @@ TODO: { } # remove this closure once the TODO above is working -my $w; { - local $SIG{__WARN__} = sub { $w = shift }; + my $warn_re = qr/will explode the number of row objects retrievable via/; + + my (@w, @dummy); + local $SIG{__WARN__} = sub { $_[0] =~ $warn_re ? push @w, @_ : warn @_ }; my $rs = $schema->resultset('CD')->search ({ 'me.title' => 'Forkful of bees' }, { prefetch => [qw/tracks tags/] }); - for (qw/all count next first/) { - undef $w; - my @stuff = $rs->search()->$_; - like ($w, qr/will currently disrupt both the functionality of .rs->count\(\), and the amount of objects retrievable via .rs->next\(\)/, - "warning on ->$_ attempt prefetching several same level has_manys (1 -> M + M)"); - } + @w = (); + @dummy = $rs->first; + is (@w, 1, 'warning on attempt prefetching several same level has_manys (1 -> M + M)'); + my $rs2 = $schema->resultset('LinerNotes')->search ({ notes => 'Buy Whiskey!' }, { prefetch => { cd => [qw/tags tracks/] } }); - for (qw/all count next first/) { - undef $w; - my @stuff = $rs2->search()->$_; - like ($w, qr/will currently disrupt both the functionality of .rs->count\(\), and the amount of objects retrievable via .rs->next\(\)/, - "warning on ->$_ attempt prefetching several same level has_manys (M -> 1 -> M + M)"); - } + @w = (); + @dummy = $rs2->first; + is (@w, 1, 'warning on attempt prefetching several same level has_manys (M -> 1 -> M + M)'); } __END__