From: Daniel Ruoso Date: Wed, 24 Nov 2010 18:26:20 +0000 (-0300) Subject: eager check if the create_related is at all possible X-Git-Tag: v0.08190~1^2~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1115a4219b76d4ac212fb91f24ff33e3f95b4e88;p=dbsrgits%2FDBIx-Class.git eager check if the create_related is at all possible When calling create_related, it should stop trying if the extended rel does not provide the complete relationship definition. --- diff --git a/lib/DBIx/Class/Relationship/Base.pm b/lib/DBIx/Class/Relationship/Base.pm index 3d0b44c..1853db3 100644 --- a/lib/DBIx/Class/Relationship/Base.pm +++ b/lib/DBIx/Class/Relationship/Base.pm @@ -567,6 +567,20 @@ in L for details. sub create_related { my $self = shift; my $rel = shift; + + # we need to stop and check if this is at all possible. If this is + # an extended relationship with an incomplete definition, we should + # just forbid it right now. + my $rel_info = $self->result_source->relationship_info($rel); + if (ref $rel_info->{cond} eq 'CODE') { + my ($cond, $ext) = $rel_info->{cond}->({ self_alias => 'me', + foreign_alias => 'other', + self_rowobj => $self + }); + $self->throw_exception("unable to set_from_related - no simplified condition available for '${rel}'") + unless $ext; + } + my $obj = $self->search_related($rel)->create(@_); delete $self->{related_resultsets}->{$rel}; return $obj;