[Dbix-class] Cascade deletes

Bill Moseley moseley at hank.org
Tue Mar 9 22:23:03 GMT 2010


On Sat, Mar 6, 2010 at 1:24 AM, Pedro Melo <melo at simplicidade.org> wrote:

>  > First, is there a way to globally disable cascade deletes?
>
> I did that once for exactly the same reasons. Created a DBIC component
> that overrides add_relationship(). The fourth parameter is the hashref
> with the options, set cascade_delete =3D> 0 and call the next method.
>

I just added this to my Result base class.  Look similar to what you are
doing?  True, a component is probably a better long-term solution.

sub add_relationship {
    my ( $self, @rest ) =3D @_;

    my $options =3D $rest[3];
    if ( ref $options eq 'HASH' ) {
        for ( qw/ cascade_delete cascade_copy / ) {
            $options->{$_} =3D 0 if $options->{$_};
        }
    }

    return $self->next::method( @rest );
}

(Seems like it would be a rare case where cascade_copy would be desired.)







-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20100309/d66=
749ca/attachment.htm


More information about the DBIx-Class mailing list