From: David Kamholz Date: Sat, 10 Dec 2005 15:06:51 +0000 (+0000) Subject: - updated manifest and manifest.skip X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7b6017716effef9d7467a9d8ef68068b3720a2e0;p=dbsrgits%2FDBIx-Class-Historic.git - updated manifest and manifest.skip - added support in BelongsTo for string third argument specifying foreign column name (and test) --- diff --git a/MANIFEST b/MANIFEST index 2ff9869..655bea9 100644 --- a/MANIFEST +++ b/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 diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP index 1977a1e..261402e 100644 --- a/MANIFEST.SKIP +++ b/MANIFEST.SKIP @@ -24,6 +24,9 @@ \#$ \b\.# +# avoid OS X finder files +\.DS_Store$ + # Don't ship the test db ^t/var diff --git a/lib/DBIx/Class/Relationship/BelongsTo.pm b/lib/DBIx/Class/Relationship/BelongsTo.pm index f59f532..ef6f904 100644 --- a/lib/DBIx/Class/Relationship/BelongsTo.pm +++ b/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; } diff --git a/t/lib/DBICTest/Schema/HelperRels.pm b/t/lib/DBICTest/Schema/HelperRels.pm index bd74259..2f99d7b 100644 --- a/t/lib/DBICTest/Schema/HelperRels.pm +++ b/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');