better error messages, throw an exception if we try to set up a relationship

without a primary key.
This commit is contained in:
espie 2006-12-06 15:09:08 +00:00
parent ce1f51b467
commit c22127d6a0
3 changed files with 30 additions and 1 deletions

View File

@ -1,9 +1,10 @@
# $OpenBSD: Makefile,v 1.2 2006/11/23 18:46:27 espie Exp $
# $OpenBSD: Makefile,v 1.3 2006/12/06 15:09:08 espie Exp $
COMMENT= "object-oriented database access"
MODULES= cpan
DISTNAME= DBIx-Class-0.07003
PKGNAME= p5-${DISTNAME}p0
CATEGORIES= databases devel
# Artistic

View File

@ -0,0 +1,14 @@
$OpenBSD: patch-lib_DBIx_Class_Relationship_HasMany_pm,v 1.1 2006/12/06 15:09:08 espie Exp $
--- 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;

View File

@ -0,0 +1,14 @@
$OpenBSD: patch-lib_DBIx_Class_Relationship_HasOne_pm,v 1.1 2006/12/06 15:09:08 espie Exp $
--- 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) {