From: Peter Rabbitson Date: Sun, 22 Feb 2009 12:43:54 +0000 (+0000) Subject: fix exception on esoteric new_related (by zby) X-Git-Tag: v0.08240~62 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f623c6ee5de411b8a231abf80f65b33a117878a3;p=dbsrgits%2FDBIx-Class.git fix exception on esoteric new_related (by zby) --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 92cbbd7..ed603c5 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1700,7 +1700,7 @@ sub new_result { defined $self->{cond} && $self->{cond} eq $DBIx::Class::ResultSource::UNRESOLVABLE_CONDITION ) { - %new = %{$self->{attrs}{related_objects}}; + %new = %{ $self->{attrs}{related_objects} || {} }; # nothing might have been inserted yet $new{-from_resultset} = [ keys %new ] if keys %new; } else { $self->throw_exception( diff --git a/t/66relationship.t b/t/66relationship.t index 3b67e45..798e660 100644 --- a/t/66relationship.t +++ b/t/66relationship.t @@ -8,7 +8,7 @@ use DBICTest; my $schema = DBICTest->init_schema(); -plan tests => 69; +plan tests => 70; # has_a test my $cd = $schema->resultset("CD")->find(4); @@ -138,6 +138,15 @@ my $newartist = $cd->find_or_new_related( 'artist', { is($newartist->name, 'Random Boy Band Two', 'find_or_new_related new artist record with id'); is($newartist->id, 200, 'find_or_new_related new artist id set'); +lives_ok( + sub { + my $new_bookmark = $schema->resultset("Bookmark")->new_result( {} ); + my $new_related_link = $new_bookmark->new_related( 'link', {} ); + }, + 'No back rel' +); + + TODO: { local $TODO = "relationship checking needs fixing"; # try to add a bogus relationship using the wrong cols