Hi,

On Tue, Mar 9, 2010 at 10:23 PM, Bill Moseley <[email protected]> wrote:
> On Sat, Mar 6, 2010 at 1:24 AM, Pedro Melo <[email protected]> wrote:
>> 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 => 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.

It was client work, I don't have access to the code anymore. But it
looks good. See below for two improvements.

> sub add_relationship {
>     my ( $self, @rest ) = @_;
>     my $options = $rest[3];
>     if ( ref $options eq 'HASH' ) {
>         for ( qw/ cascade_delete cascade_copy / ) {
>             $options->{$_} = 0 if $options->{$_};
>         }
>     }
>     return $self->next::method( @rest );
> }

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

    # Make sure we have options
    # If we want to force cascade_* stuff
    my $options = $rest[3] ||= {};
    for ( qw/ cascade_delete cascade_copy / ) {
        # Any user-defined value wins
        $options->{$_} = 0 unless exists $options->{$_};
    }

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

Bye,
-- 
Pedro Melo
http://www.simplicidade.org/
xmpp:[email protected]
mailto:[email protected]

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]

Reply via email to