From: Matt S Trout Date: Tue, 6 Nov 2007 14:53:48 +0000 (+0000) Subject: make belongs_to accept an [] join cond X-Git-Tag: v0.08010~36 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4ff1b819f21a2fe72d46008920639bd25b9dbb8f;hp=ef7a8b67862cb8d034591cdc564945dc2c7a61a4;p=dbsrgits%2FDBIx-Class.git make belongs_to accept an [] join cond --- diff --git a/lib/DBIx/Class/Relationship/BelongsTo.pm b/lib/DBIx/Class/Relationship/BelongsTo.pm index b871266..5756f2b 100644 --- a/lib/DBIx/Class/Relationship/BelongsTo.pm +++ b/lib/DBIx/Class/Relationship/BelongsTo.pm @@ -41,20 +41,25 @@ sub belongs_to { ); } # explicit join condition - elsif (ref $cond eq 'HASH') { - my $cond_rel; - for (keys %$cond) { - if (m/\./) { # Explicit join condition - $cond_rel = $cond; - last; + elsif (ref $cond) { + if (ref $cond eq 'HASH') { # ARRAY is also valid + my $cond_rel; + for (keys %$cond) { + if (m/\./) { # Explicit join condition + $cond_rel = $cond; + last; + } + $cond_rel->{"foreign.$_"} = "self.".$cond->{$_}; } - $cond_rel->{"foreign.$_"} = "self.".$cond->{$_}; + $cond = $cond_rel; } - my $acc_type = (keys %$cond_rel == 1 and $class->has_column($rel)) - ? 'filter' - : 'single'; + my $acc_type = ((ref $cond eq 'HASH') + && keys %$cond == 1 + && $class->has_column($rel)) + ? 'filter' + : 'single'; $class->add_relationship($rel, $f_class, - $cond_rel, + $cond, { accessor => $acc_type, %{$attrs || {}} } ); }