From: Dagfinn Ilmari Mannsåker Date: Tue, 1 Oct 2013 19:04:22 +0000 (+0100) Subject: Throw clearer exception on ->new_related() with a non-existent relationship X-Git-Tag: v0.08260~138 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3f8affda61edb3a04cf3ed3b8349c06f3d5c7858;p=dbsrgits%2FDBIx-Class.git Throw clearer exception on ->new_related() with a non-existent relationship --- diff --git a/Changes b/Changes index d42f06f..11dfb01 100644 --- a/Changes +++ b/Changes @@ -12,6 +12,8 @@ Revision history for DBIx::Class - Back out self-cleaning from DBIx::Class::Carp for the time being (as a side effect fixes RT#86267) - Tests no longer fail if $ENV{DBI_DSN} is set + - Throw clearer exception on ->new_related() with a non-existent + relationship. * Misc - Replace $row with $result in all docs to be consistent and to diff --git a/lib/DBIx/Class/Relationship/Base.pm b/lib/DBIx/Class/Relationship/Base.pm index 23ce915..20a9c17 100644 --- a/lib/DBIx/Class/Relationship/Base.pm +++ b/lib/DBIx/Class/Relationship/Base.pm @@ -640,8 +640,10 @@ sub new_related { if (ref $self) { # cdbi calls this as a class method, /me vomits my $rsrc = $self->result_source; + my $rel_info = $rsrc->relationship_info($rel) + or $self->throw_exception( "No such relationship '$rel'" ); my (undef, $crosstable, $cond_targets) = $rsrc->_resolve_condition ( - $rsrc->relationship_info($rel)->{cond}, $rel, $self, $rel + $rel_info->{cond}, $rel, $self, $rel ); $self->throw_exception("Custom relationship '$rel' does not resolve to a join-free condition fragment") diff --git a/t/relationship/core.t b/t/relationship/core.t index 23d829d..e86dfc6 100644 --- a/t/relationship/core.t +++ b/t/relationship/core.t @@ -136,6 +136,10 @@ lives_ok( 'No back rel' ); +throws_ok { + my $new_bookmark = $schema->resultset("Bookmark")->new_result( {} ); + $new_bookmark->new_related( no_such_rel => {} ); +} qr/No such relationship 'no_such_rel'/, 'creating in uknown rel throws'; { local $TODO = "relationship checking needs fixing";