X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FRelationship%2FBase.pm;h=b4984e72e65ece4fcdc7ee4a38fc76d40eb775ff;hb=cee0c9b187a09934aa46cafb2d1cc78a1b6e9eae;hp=17de514ac92463b21e16dfbc6511d37f9e99d912;hpb=48580715af3072905f2c71dc27e7f70f21a11338;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Relationship/Base.pm b/lib/DBIx/Class/Relationship/Base.pm index 17de514..b4984e7 100644 --- a/lib/DBIx/Class/Relationship/Base.pm +++ b/lib/DBIx/Class/Relationship/Base.pm @@ -122,6 +122,37 @@ is creating constraints where it shouldn't, or not creating them where it should, set this attribute to a true or false value to override the detection of when to create constraints. +=item cascade_copy + +If C is true on a C relationship for an +object, then when you copy the object all the related objects will +be copied too. To turn this behaviour off, pass C<< cascade_copy => 0 >> +in the C<$attr> hashref. The behaviour defaults to C<< cascade_copy => 1 >>. + +=item cascade_delete + +By default, DBIx::Class cascades deletes across C and +C relationships. You can disable this behaviour on a +per-relationship basis by supplying C<< cascade_delete => 0 >> in the +relationship attributes. + +The cascaded operations are performed after the requested delete, +so if your database has a constraint on the relationship, it will +have deleted/updated the related records or raised an exception +before DBIx::Class gets to perform the cascaded operation. + +=item cascade_update + +By default, DBIx::Class cascades updates across C and +C relationships. You can disable this behaviour on a +per-relationship basis by supplying C<< cascade_update => 0 >> in the +relationship attributes. + +This is not a RDMS style cascade update - it purely means that when +an object has update called on it, all the related objects also +have update called. It will not change foreign keys automatically - +you must arrange to do this yourself. + =item on_delete / on_update If you are using L to create SQL for you, you can use these @@ -200,9 +231,19 @@ sub related_resultset { my $query = ((@_ > 1) ? {@_} : shift); my $source = $self->result_source; - my $cond = $source->_resolve_condition( - $rel_info->{cond}, $rel, $self - ); + + # condition resolution may fail if an incomplete master-object prefetch + # is encountered - that is ok during prefetch construction (not yet in_storage) + my $cond = eval { $source->_resolve_condition( $rel_info->{cond}, $rel, $self ) }; + if (my $err = $@) { + if ($self->in_storage) { + $self->throw_exception ($err); + } + else { + $cond = $DBIx::Class::ResultSource::UNRESOLVABLE_CONDITION; + } + } + if ($cond eq $DBIx::Class::ResultSource::UNRESOLVABLE_CONDITION) { my $reverse = $source->reverse_relationship_info($rel); foreach my $rev_rel (keys %$reverse) {