Skip to content

Commit

Permalink
Fix the join/prefetch resolver when dealing with ''/undef/()
Browse files Browse the repository at this point in the history
  • Loading branch information
ribasushi committed Nov 26, 2011
1 parent 6c30f9c commit 8bc4746
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Changes
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/DBIx/Class/ResultSet.pm
Expand Up @@ -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 );
Expand Down
4 changes: 2 additions & 2 deletions lib/DBIx/Class/ResultSource.pm
Expand Up @@ -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') {
Expand Down Expand Up @@ -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' ) {
Expand Down
10 changes: 10 additions & 0 deletions t/prefetch/diamond.t
Expand Up @@ -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'}]
};
Expand Down

0 comments on commit 8bc4746

Please sign in to comment.