1 package # hide from PAUSE
2 DBIx::Class::Relationship::CascadeActions;
7 our %_pod_inherit_config =
9 class_map => { 'DBIx::Class::Relationship::CascadeActions' => 'DBIx::Class::Relationship' }
13 my ($self, @rest) = @_;
14 return $self->next::method(@rest) unless ref $self;
15 # I'm just ignoring this for class deletes because hell, the db should
16 # be handling this anyway. Assuming we have joins we probably actually
17 # *could* do them, but I'd rather not.
19 my $source = $self->result_source;
20 my %rels = map { $_ => $source->relationship_info($_) } $source->relationships;
21 my @cascade = grep { $rels{$_}{attrs}{cascade_delete} } keys %rels;
24 my $guard = $source->schema->txn_scope_guard;
26 my $ret = $self->next::method(@rest);
28 foreach my $rel (@cascade) {
29 $self->search_related($rel)->delete_all;
36 $self->next::method(@rest);
40 my ($self, @rest) = @_;
41 return $self->next::method(@rest) unless ref $self;
42 # Because update cascades on a class *really* don't make sense!
44 my $source = $self->result_source;
45 my %rels = map { $_ => $source->relationship_info($_) } $source->relationships;
46 my @cascade = grep { $rels{$_}{attrs}{cascade_update} } keys %rels;
49 my $guard = $source->schema->txn_scope_guard;
51 my $ret = $self->next::method(@rest);
53 foreach my $rel (@cascade) {
55 $rels{$rel}{attrs}{accessor}
57 $rels{$rel}{attrs}{accessor} eq 'single'
59 !exists($self->{_relationship_data}{$rel})
61 $_->update for grep defined, $self->$rel;
68 $self->next::method(@rest);