Skip to content

Commit 8bc4746

Browse files
committed
Fix the join/prefetch resolver when dealing with ''/undef/()
1 parent 6c30f9c commit 8bc4746

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

Changes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Revision history for DBIx::Class
1717
- Fix test failures on perl < 5.8.7 and new Package::Stash::XS
1818
- Fix TxnScopeGuard not behaving correctly when $@ is set at the
1919
time of $guard instantiation
20+
- Fix the join/prefetch resolver when dealing with ''/undef/()
21+
relation specifications
2022

2123
* Misc
2224
- No longer depend on Variable::Magic now that a pure-perl

lib/DBIx/Class/ResultSet.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3440,6 +3440,7 @@ sub _merge_joinpref_attr {
34403440
$position++;
34413441
}
34423442
my ($import_key) = ( ref $import_element eq 'HASH' ) ? keys %{$import_element} : ($import_element);
3443+
$import_key = '' if not defined $import_key;
34433444

34443445
if ($best_candidate->{score} == 0 || exists $seen_keys->{$import_key}) {
34453446
push( @{$orig}, $import_element );

lib/DBIx/Class/ResultSource.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,7 +1461,7 @@ sub _resolve_join {
14611461

14621462
$jpath = [@$jpath]; # copy
14631463

1464-
if (not defined $join) {
1464+
if (not defined $join or not length $join) {
14651465
return ();
14661466
}
14671467
elsif (ref $join eq 'ARRAY') {
@@ -1728,7 +1728,7 @@ sub _resolve_prefetch {
17281728
my ($self, $pre, $alias, $alias_map, $order, $collapse, $pref_path) = @_;
17291729
$pref_path ||= [];
17301730

1731-
if (not defined $pre) {
1731+
if (not defined $pre or not length $pre) {
17321732
return ();
17331733
}
17341734
elsif( ref $pre eq 'ARRAY' ) {

t/prefetch/diamond.t

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,21 @@ my $ars = $schema->resultset ('Artwork');
3838

3939
my $cd_paths = {
4040
'no cd' => [],
41+
'no cd empty' => [ '' ],
42+
'no cd undef' => [ undef ],
43+
'no cd href' => [ {} ],
44+
'no cd aoh' => [ [{}] ],
45+
'no cd complex' => [ [ [ undef ] ] ],
4146
'cd' => ['cd'],
4247
'cd->artist1' => [{'cd' => 'artist'}]
4348
};
4449
my $a2a_paths = {
4550
'no a2a' => [],
51+
'no a2a empty ' => [ '' ],
52+
'no a2a undef' => [ undef ],
53+
'no a2a href' => [ {} ],
54+
'no a2a aoh' => [ [{}] ],
55+
'no a2a complex' => [ [ '' ] ],
4656
'a2a' => ['artwork_to_artist'],
4757
'a2a->artist2' => [{'artwork_to_artist' => 'artist'}]
4858
};

0 commit comments

Comments
 (0)