Permalink
Browse files

- updated manifest and manifest.skip

- added support in BelongsTo for string third argument specifying foreign column name (and test)
  • Loading branch information...
1 parent 1240ad9 commit 7b6017716effef9d7467a9d8ef68068b3720a2e0 David Kamholz committed Dec 10, 2005
Showing with 22 additions and 7 deletions.
  1. +2 −0 MANIFEST
  2. +3 −0 MANIFEST.SKIP
  3. +16 −6 lib/DBIx/Class/Relationship/BelongsTo.pm
  4. +1 −1 t/lib/DBICTest/Schema/HelperRels.pm
View
@@ -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
@@ -24,6 +24,9 @@
\#$
\b\.#
+# avoid OS X finder files
+\.DS_Store$
+
# Don't ship the test db
^t/var
@@ -13,20 +13,27 @@ 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}" },
{ accessor => $acc_type, %{$attrs || {}} }
);
}
# 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;
}
@@ -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.