Corrected columns_info_for indent level - 2 space indent everyone please, you may...
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Relationship / CascadeActions.pm
CommitLineData
c0e7b4e5 1package # hide from PAUSE
2 DBIx::Class::Relationship::CascadeActions;
4a07648a 3
4sub delete {
5 my ($self, @rest) = @_;
147dd158 6 return $self->next::method(@rest) unless ref $self;
4a07648a 7 # I'm just ignoring this for class deletes because hell, the db should
8 # be handling this anyway. Assuming we have joins we probably actually
9 # *could* do them, but I'd rather not.
10
147dd158 11 my $ret = $self->next::method(@rest);
4a07648a 12
71e65b39 13 my $source = $self->result_source;
14 my %rels = map { $_ => $source->relationship_info($_) } $source->relationships;
4a07648a 15 my @cascade = grep { $rels{$_}{attrs}{cascade_delete} } keys %rels;
16 foreach my $rel (@cascade) {
503536d5 17 $self->search_related($rel)->delete;
4a07648a 18 }
19 return $ret;
20}
21
22sub update {
23 my ($self, @rest) = @_;
147dd158 24 return $self->next::method(@rest) unless ref $self;
4a07648a 25 # Because update cascades on a class *really* don't make sense!
26
147dd158 27 my $ret = $self->next::method(@rest);
4a07648a 28
71e65b39 29 my $source = $self->result_source;
30 my %rels = map { $_ => $source->relationship_info($_) } $source->relationships;
4a07648a 31 my @cascade = grep { $rels{$_}{attrs}{cascade_update} } keys %rels;
32 foreach my $rel (@cascade) {
33 $_->update for $self->$rel;
34 }
35 return $ret;
36}
37
381;