X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FRelationship%2FHasMany.pm;h=d8e651d470c8ea7715c973ee24e241dbfb1ba535;hb=f43ea814d6c4c181aeaac244c5db17058aac3d5e;hp=6bdefd472eaf27b2521da14b754b84d73774340a;hpb=893fef20189e668794439fdf7b17054902fce28f;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/Relationship/HasMany.pm b/lib/DBIx/Class/Relationship/HasMany.pm index 6bdefd4..d8e651d 100644 --- a/lib/DBIx/Class/Relationship/HasMany.pm +++ b/lib/DBIx/Class/Relationship/HasMany.pm @@ -3,13 +3,22 @@ package # hide from PAUSE use strict; use warnings; +use Try::Tiny; + +our %_pod_inherit_config = + ( + class_map => { 'DBIx::Class::Relationship::HasMany' => 'DBIx::Class::Relationship' } + ); sub has_many { my ($class, $rel, $f_class, $cond, $attrs) = @_; unless (ref $cond) { $class->ensure_class_loaded($f_class); - my ($pri, $too_many) = $class->primary_columns; + my ($pri, $too_many) = try { $class->_pri_cols } + catch { + $class->throw_exception("Can't infer join condition for ${rel} on ${class}: $_"); + }; $class->throw_exception( "has_many can only infer join for a single primary key; ". @@ -31,11 +40,11 @@ sub has_many { $guess = "using our class name '$class' as foreign key"; } - my $f_class_loaded = eval { $f_class->columns }; + my $f_class_loaded = try { $f_class->columns }; $class->throw_exception( "No such column ${f_key} on foreign class ${f_class} ($guess)" ) if $f_class_loaded && !$f_class->has_column($f_key); - + $cond = { "foreign.${f_key}" => "self.${pri}" }; }