Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- updated manifest and manifest.skip

- added support in BelongsTo for string third argument specifying foreign column name (and test)
  • Loading branch information...
commit 7b6017716effef9d7467a9d8ef68068b3720a2e0 1 parent 1240ad9
David Kamholz authored
View
2  MANIFEST
@@ -67,7 +67,9 @@ META.yml
README
t/02pod.t
t/03podcoverage.t
+t/04dont_break_c3.t
t/19quotes.t
+t/20setuperrors.t
t/basicrels/01core.t
t/basicrels/04db.t
t/basicrels/05multipk.t
View
3  MANIFEST.SKIP
@@ -24,6 +24,9 @@
\#$
\b\.#
+# avoid OS X finder files
+\.DS_Store$
+
# Don't ship the test db
^t/var
View
22 lib/DBIx/Class/Relationship/BelongsTo.pm
@@ -13,12 +13,19 @@ sub belongs_to {
my %f_primaries;
$f_primaries{$_} = 1 for eval { $f_class->primary_columns };
my $f_loaded = !$@;
+
# single key relationship
- if (not defined $cond) {
- $class->throw("Can't infer join condition for ${rel} on ${class}; unable to load ${f_class}") unless $f_loaded;
- my ($pri, $too_many) = keys %f_primaries;
- $class->throw("Can't infer join condition for ${rel} on ${class}; ${f_class} has multiple primary key") if $too_many;
- $class->throw("Can't find any primary keys for $f_class, try adding some") if !$pri;
+ if (!ref $cond) {
+ my ($pri,$too_many);
+ if (!defined $cond) {
+ $class->throw("Can't infer join condition for ${rel} on ${class}; unable to load ${f_class}") unless $f_loaded;
+ ($pri, $too_many) = keys %f_primaries;
+ $class->throw("Can't infer join condition for ${rel} on ${class}; ${f_class} has no primary keys") unless defined $pri;
+ $class->throw("Can't infer join condition for ${rel} on ${class}; ${f_class} has multiple primary key") if $too_many;
+ }
+ else {
+ $pri = $cond;
+ }
my $acc_type = ($class->has_column($rel)) ? 'filter' : 'single';
$class->add_relationship($rel, $f_class,
{ "foreign.${pri}" => "self.${rel}" },
@@ -26,7 +33,7 @@ sub belongs_to {
);
}
# multiple key relationship
- else {
+ elsif (ref $cond eq 'HASH') {
my $cond_rel;
for (keys %$cond) {
if (m/\./) { # Explicit join condition
@@ -40,6 +47,9 @@ sub belongs_to {
{ accessor => 'single', %{$attrs || {}} }
);
}
+ else {
+ $class->throw('third argument for belongs_to must be undef, a column name, or a join condition');
+ }
return 1;
}
View
2  t/lib/DBICTest/Schema/HelperRels.pm
@@ -26,7 +26,7 @@ DBICTest::Schema::SelfRef->has_many(
DBICTest::Schema::Tag->belongs_to('cd', 'DBICTest::Schema::CD');
-DBICTest::Schema::Track->belongs_to('cd', 'DBICTest::Schema::CD');
+DBICTest::Schema::Track->belongs_to('cd', 'DBICTest::Schema::CD', 'cdid');
DBICTest::Schema::TwoKeys->belongs_to('artist', 'DBICTest::Schema::Artist');

0 comments on commit 7b60177

Please sign in to comment.
Something went wrong with that request. Please try again.