From: Matt S Trout Date: Tue, 2 Aug 2005 05:27:21 +0000 (+0000) Subject: Made add_relationship remove the relationship entry before it dies X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d322f982dd1f176bf4301552d6a51376045ce451;p=dbsrgits%2FDBIx-Class-Historic.git Made add_relationship remove the relationship entry before it dies --- diff --git a/lib/DBIx/Class/Relationship.pm b/lib/DBIx/Class/Relationship.pm index 9b405e9..def2733 100644 --- a/lib/DBIx/Class/Relationship.pm +++ b/lib/DBIx/Class/Relationship.pm @@ -36,12 +36,19 @@ sub add_relationship { attrs => $attrs }; $class->_relationships(\%rels); #warn %{$f_class->_columns}; + return unless eval { %{$f_class->_columns}; }; # Foreign class not loaded my %join = (%$attrs, _action => 'join', _aliases => { 'self' => 'me', 'foreign' => $rel }, _classes => { 'me' => $class, $rel => $f_class }); eval { $class->_cond_resolve($cond, \%join) }; - $class->throw("Error creating relationship $rel: $@") if $@; + + if ($@) { # If the resolve failed, back out and re-throw the error + delete $rels{$rel}; # + $class->_relationships(\%rels); + $class->throw("Error creating relationship $rel: $@"); + } + 1; } sub _cond_key {