From: Ash Berlin Date: Wed, 6 Dec 2006 21:48:49 +0000 (+0000) Subject: More descriptive error messages courtesy of Marc Espie X-Git-Tag: v0.08010~210 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e36de82e983b60c6621c9458f686f1073b6a8f6b;p=dbsrgits%2FDBIx-Class.git More descriptive error messages courtesy of Marc Espie --- diff --git a/lib/DBIx/Class/Relationship/HasMany.pm b/lib/DBIx/Class/Relationship/HasMany.pm index 2c9a3bb..6bdefd4 100644 --- a/lib/DBIx/Class/Relationship/HasMany.pm +++ b/lib/DBIx/Class/Relationship/HasMany.pm @@ -16,6 +16,11 @@ sub has_many { "${class} has more" ) if $too_many; + $class->throw_exception( + "has_many needs a primary key to infer a join; ". + "${class} has none" + ) if !defined $pri && (!defined $cond || !length $cond); + my ($f_key,$guess); if (defined $cond && length $cond) { $f_key = $cond; diff --git a/lib/DBIx/Class/Relationship/HasOne.pm b/lib/DBIx/Class/Relationship/HasOne.pm index 568078c..543649b 100644 --- a/lib/DBIx/Class/Relationship/HasOne.pm +++ b/lib/DBIx/Class/Relationship/HasOne.pm @@ -17,10 +17,17 @@ sub _has_one { unless (ref $cond) { $class->ensure_class_loaded($f_class); my ($pri, $too_many) = $class->primary_columns; + $class->throw_exception( "might_have/has_one can only infer join for a single primary key; ". "${class} has more" ) if $too_many; + + $class->throw_exception( + "might_have/has_one needs a primary key to infer a join; ". + "${class} has none" + ) if !defined $pri && (!defined $cond || !length $cond); + my $f_class_loaded = eval { $f_class->columns }; my ($f_key,$guess); if (defined $cond && length $cond) {