[PATCH] Better error message for Relationship/HasA.pm

[prev] [thread] [next] [Date index for 2005/06/07]

From: Drew Taylor
Subject: [PATCH] Better error message for Relationship/HasA.pm
Date: 20:48 on 07 Jun 2005
------=_Part_2103_22496801.1118177303537
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

I recently spent 20 minutes tracking down a problem that turned out to be=
=20
trying to define a has_a relationship on a column I had previously removed.=
=20
This patch adds a more descriptive error message. It's trivial but it would=
=20
have saved me some time last week.

Drew

--- HasA.pm.orig Tue Jun 7 16:43:02 2005
+++ HasA.pm <http://HasA.pm>; Tue Jun 7 16:45:15 2005
@@ -9,8 +9,9 @@
my $proto =3D shift;
my $class =3D shift;
$class->_invalid_object_method('has_a()') if ref $class;
- my $column =3D $class->find_column(+shift)
- or return $class->_croak("has_a needs a valid column");
+ my $requested_col =3D shift;
+ my $column =3D $class->find_column($requested_col)
+ or return $class->_croak("has_a needs a valid column - $requested_col doe=
s=20
not exist");
my $a_class =3D shift
or $class->_croak("$class $column needs an associated class");
my %meths =3D @_;


--=20
----------------------------------------------------------------
Drew Taylor * Web development & consulting
Email: drew@xxxxxxxxxx.xxx * Site implementation & hosting
Web : www.drewtaylor.com <http://www.drewtaylor.com>; *=20
perl/mod_perl/DBI/mysql/postgres
----------------------------------------------------------------

------=_Part_2103_22496801.1118177303537
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

I recently spent 20 minutes tracking down a problem that turned out to
be trying to define a has_a relationship on a column I had previously
removed. This patch adds a more descriptive error message. It's trivial
but it would have saved me some time last week.<br>
<br>
Drew<br>
<br>
--- HasA.pm.orig&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tue Jun&nbsp; 7 =
16:43:02 2005<br>
+++ <a href=3D"http://HasA.pm">HasA.pm</a>&nbsp;&nbsp;&nbsp;&nbsp; Tue Jun&=
nbsp; 7 16:45:15 2005<br>
@@ -9,8 +9,9 @@<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $proto =3D shift;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $class =3D shift;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $class-&gt;_invalid_object_metho=
d('has_a()') if ref $class;<br>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $column =3D $class-&gt;find_column=
(+shift)<br>
-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;
or return $class-&gt;_croak(&quot;has_a needs a valid column&quot;);<br>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $requested_col =3D shift;<br=
>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $column =3D $class-&gt;find_column=
($requested_col)<br>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;
or return $class-&gt;_croak(&quot;has_a needs a valid column -
$requested_col does not exist&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $a_class =3D shift<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;
or $class-&gt;_croak(&quot;$class $column needs an associated class&quot;);=
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my %meths =3D @_;<br>
<br><br>-- <br>------------------------------------------------------------=
----<br>
Drew
Taylor&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;
*&nbsp;&nbsp;Web development &amp; consulting<br> Email: <a href=3D"mailto:=
drew@xxxxxxxxxx.xxx">drew@xxxxxxxxxx.xxx</a>&nbsp;&nbsp;*&nbsp;&nbsp;Site i=
mplementation &amp; hosting<br> Web&nbsp;&nbsp;: <a href=3D"http://www.drew=
taylor.com">www.drewtaylor.com</a>&nbsp;&nbsp; *&nbsp;&nbsp;perl/mod_perl/D=
BI/mysql/postgres
<br> ----------------------------------------------------------------

------=_Part_2103_22496801.1118177303537--

[PATCH] Better error message for Relationship/HasA.pm
Drew Taylor 20:48 on 07 Jun 2005

Generated at 16:36 on 28 Jul 2005 by mariachi v0.52