From: Peter Rabbitson Date: Sat, 26 Nov 2011 01:41:16 +0000 (+0100) Subject: Fix the join/prefetch resolver when dealing with ''/undef/() X-Git-Tag: v0.08196~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8bc474676193d8832932f01cc60f85e7c1d44c76;p=dbsrgits%2FDBIx-Class.git Fix the join/prefetch resolver when dealing with ''/undef/() --- diff --git a/Changes b/Changes index 895bb70..69fc7ba 100644 --- a/Changes +++ b/Changes @@ -17,6 +17,8 @@ Revision history for DBIx::Class - Fix test failures on perl < 5.8.7 and new Package::Stash::XS - Fix TxnScopeGuard not behaving correctly when $@ is set at the time of $guard instantiation + - Fix the join/prefetch resolver when dealing with ''/undef/() + relation specifications * Misc - No longer depend on Variable::Magic now that a pure-perl diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index dee7c30..d883551 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -3440,6 +3440,7 @@ sub _merge_joinpref_attr { $position++; } my ($import_key) = ( ref $import_element eq 'HASH' ) ? keys %{$import_element} : ($import_element); + $import_key = '' if not defined $import_key; if ($best_candidate->{score} == 0 || exists $seen_keys->{$import_key}) { push( @{$orig}, $import_element ); diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index 75287bd..c523745 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -1461,7 +1461,7 @@ sub _resolve_join { $jpath = [@$jpath]; # copy - if (not defined $join) { + if (not defined $join or not length $join) { return (); } elsif (ref $join eq 'ARRAY') { @@ -1728,7 +1728,7 @@ sub _resolve_prefetch { my ($self, $pre, $alias, $alias_map, $order, $collapse, $pref_path) = @_; $pref_path ||= []; - if (not defined $pre) { + if (not defined $pre or not length $pre) { return (); } elsif( ref $pre eq 'ARRAY' ) { diff --git a/t/prefetch/diamond.t b/t/prefetch/diamond.t index 0de8009..9dbea1a 100644 --- a/t/prefetch/diamond.t +++ b/t/prefetch/diamond.t @@ -38,11 +38,21 @@ my $ars = $schema->resultset ('Artwork'); my $cd_paths = { 'no cd' => [], + 'no cd empty' => [ '' ], + 'no cd undef' => [ undef ], + 'no cd href' => [ {} ], + 'no cd aoh' => [ [{}] ], + 'no cd complex' => [ [ [ undef ] ] ], 'cd' => ['cd'], 'cd->artist1' => [{'cd' => 'artist'}] }; my $a2a_paths = { 'no a2a' => [], + 'no a2a empty ' => [ '' ], + 'no a2a undef' => [ undef ], + 'no a2a href' => [ {} ], + 'no a2a aoh' => [ [{}] ], + 'no a2a complex' => [ [ '' ] ], 'a2a' => ['artwork_to_artist'], 'a2a->artist2' => [{'artwork_to_artist' => 'artist'}] };