[Dbix-class] Cascade deletes
Pedro Melo
melo at simplicidade.org
Wed Mar 10 07:23:27 GMT 2010
Hi,
On Tue, Mar 9, 2010 at 10:23 PM, Bill Moseley <moseley at hank.org> wrote:
> On Sat, Mar 6, 2010 at 1:24 AM, Pedro Melo <melo at simplicidade.org> 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:melo at simplicidade.org
mailto:melo at simplicidade.org
More information about the DBIx-Class
mailing list