fix doc typo
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Relationship / CascadeActions.pm
CommitLineData
4a07648a 1package DBIx::Class::Relationship::CascadeActions;
2
3sub delete {
4 my ($self, @rest) = @_;
147dd158 5 return $self->next::method(@rest) unless ref $self;
4a07648a 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
147dd158 10 my $ret = $self->next::method(@rest);
4a07648a 11
71e65b39 12 my $source = $self->result_source;
13 my %rels = map { $_ => $source->relationship_info($_) } $source->relationships;
4a07648a 14 my @cascade = grep { $rels{$_}{attrs}{cascade_delete} } keys %rels;
15 foreach my $rel (@cascade) {
503536d5 16 $self->search_related($rel)->delete;
4a07648a 17 }
18 return $ret;
19}
20
21sub update {
22 my ($self, @rest) = @_;
147dd158 23 return $self->next::method(@rest) unless ref $self;
4a07648a 24 # Because update cascades on a class *really* don't make sense!
25
147dd158 26 my $ret = $self->next::method(@rest);
4a07648a 27
71e65b39 28 my $source = $self->result_source;
29 my %rels = map { $_ => $source->relationship_info($_) } $source->relationships;
4a07648a 30 my @cascade = grep { $rels{$_}{attrs}{cascade_update} } keys %rels;
31 foreach my $rel (@cascade) {
32 $_->update for $self->$rel;
33 }
34 return $ret;
35}
36
371;