1 package # hide from PAUSE
2 DBIx::Class::Relationship::CascadeActions;
8 my ($self, @rest) = @_;
9 return $self->next::method(@rest) unless ref $self;
10 # I'm just ignoring this for class deletes because hell, the db should
11 # be handling this anyway. Assuming we have joins we probably actually
12 # *could* do them, but I'd rather not.
14 my $ret = $self->next::method(@rest);
16 my $source = $self->result_source;
17 my %rels = map { $_ => $source->relationship_info($_) } $source->relationships;
18 my @cascade = grep { $rels{$_}{attrs}{cascade_delete} } keys %rels;
19 foreach my $rel (@cascade) {
20 $self->search_related($rel)->delete_all;
26 my ($self, @rest) = @_;
27 return $self->next::method(@rest) unless ref $self;
28 # Because update cascades on a class *really* don't make sense!
30 my $ret = $self->next::method(@rest);
32 my $source = $self->result_source;
33 my %rels = map { $_ => $source->relationship_info($_) } $source->relationships;
34 my @cascade = grep { $rels{$_}{attrs}{cascade_update} } keys %rels;
35 foreach my $rel (@cascade) {
37 $rels{$rel}{attrs}{accessor} eq 'single'
38 && !exists($self->{_relationship_data}{$rel})
40 $_->update for grep defined, $self->$rel;