Commit | Line | Data |
4a07648a |
1 | package DBIx::Class::Relationship::CascadeActions; |
2 | |
3 | sub delete { |
4 | my ($self, @rest) = @_; |
5 | return $self->NEXT::ACTUAL::delete(@rest) unless ref $self; |
6 | # I'm just ignoring this for class deletes because hell, the db should |
7 | # be handling this anyway. Assuming we have joins we probably actually |
8 | # *could* do them, but I'd rather not. |
9 | |
10 | my $ret = $self->NEXT::ACTUAL::delete(@rest); |
11 | |
12 | my %rels = %{ $self->_relationships }; |
13 | my @cascade = grep { $rels{$_}{attrs}{cascade_delete} } keys %rels; |
14 | foreach my $rel (@cascade) { |
503536d5 |
15 | $self->search_related($rel)->delete; |
4a07648a |
16 | } |
17 | return $ret; |
18 | } |
19 | |
20 | sub update { |
21 | my ($self, @rest) = @_; |
22 | return $self->NEXT::ACTUAL::update(@rest) unless ref $self; |
23 | # Because update cascades on a class *really* don't make sense! |
24 | |
25 | my $ret = $self->NEXT::ACTUAL::update(@rest); |
26 | |
27 | my %rels = %{ $self->_relationships }; |
28 | my @cascade = grep { $rels{$_}{attrs}{cascade_update} } keys %rels; |
29 | foreach my $rel (@cascade) { |
30 | $_->update for $self->$rel; |
31 | } |
32 | return $ret; |
33 | } |
34 | |
35 | 1; |