From: Peter Rabbitson Date: Thu, 18 Jun 2009 10:43:36 +0000 (+0000) Subject: HRI fix X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e8b32a6d045b4d04ba023d48be1c8e32065fcec6;p=dbsrgits%2FDBIx-Class-Historic.git HRI fix --- diff --git a/Changes b/Changes index e31367a..dc8821f 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,10 @@ Revision history for DBIx::Class + - Fixed regression when both page and offset are specified on + a resultset + - Fixed HRI returning too many empty results on multilevel + nonexisting prefetch + 0.08107 2009-06-14 08:21:00 (UTC) - Fix serialization regression introduced in 0.08103 (affects Cursor::Cached) diff --git a/lib/DBIx/Class/ResultClass/HashRefInflator.pm b/lib/DBIx/Class/ResultClass/HashRefInflator.pm index 1b3f2d1..6d019ad 100644 --- a/lib/DBIx/Class/ResultClass/HashRefInflator.pm +++ b/lib/DBIx/Class/ResultClass/HashRefInflator.pm @@ -73,8 +73,15 @@ $mk_hash = sub { # if there is at least one defined column consider the resultset real # (and not an emtpy has_many rel containing one empty hashref) + # an empty arrayref is an empty multi-sub-prefetch - don't consider + # those either for (values %$hash) { - return $hash if defined $_; + if (ref $_ eq 'ARRAY') { + return $hash if @$_; + } + elsif (defined $_) { + return $hash; + } } return undef; diff --git a/t/inflate/hri.t b/t/inflate/hri.t index 2bbaae8..1d32dd6 100644 --- a/t/inflate/hri.t +++ b/t/inflate/hri.t @@ -126,13 +126,12 @@ is_deeply [$rs_hashrefinf->all], \@hashrefinf, 'Check query using extended colum # check nested prefetching of has_many relationships which return nothing my $artist = $schema->resultset ('Artist')->create ({ name => 'unsuccessful artist without CDs'}); +$artist->discard_changes; my $rs_artists = $schema->resultset ('Artist')->search ({ 'me.artistid' => $artist->id}, { - prefetch => { cds => 'tracks' }, -}); -$rs_artists->result_class('DBIx::Class::ResultClass::HashRefInflator'); -my @artists_ok = ({ - artistid => $artist->id, - name => "unsuccessful artist without CDs", - cds => [], + prefetch => { cds => 'tracks' }, result_class => 'DBIx::Class::ResultClass::HashRefInflator', }); -is_deeply [$rs_artists->all], \@artists_ok, 'nested has_many prefetch without entries'; +is_deeply( + [$rs_artists->all], + [{ $artist->get_columns, cds => [] }], + 'nested has_many prefetch without entries' +);