From: Marc Espie <[EMAIL PROTECTED]>
Date: 6 December 2006 15:12:15 GMT
To: [EMAIL PROTECTED]
Subject: DBIx::Class patch: better error diagnostics
Reply-To: [EMAIL PROTECTED]
As I said in former messages, I'm (still) a novice to DBIx::Class, so I'm
probably qualified to comment on diagnostics ;-)
Those two patches actually helped me set up my schema correctly (yes,
they're
very simple).
I've noticed that the primary key check is the same, so it probably means
some refactoring would help more, but those were a life-saver for me.
--- lib/DBIx/Class/Relationship/HasMany.pm.orig Wed Dec 6 15:56:28
2006
+++ lib/DBIx/Class/Relationship/HasMany.pm Wed Dec 6 15:57:00 2006
@@ -16,6 +16,10 @@ 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;
my ($f_key,$guess);
if (defined $cond && length $cond) {
$f_key = $cond;
--- lib/DBIx/Class/Relationship/HasOne.pm.orig Wed Dec 6 15:57:05
2006
+++ lib/DBIx/Class/Relationship/HasOne.pm Wed Dec 6 15:58:09 2006
@@ -21,6 +21,10 @@ sub _has_one {
"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;
my $f_class_loaded = eval { $f_class->columns };
my ($f_key,$guess);
if (defined $cond && length $cond) {