Revision history for DBIx::Class
- DBIx::Class::InflateColumn::File entered deprecated state
+ - Cascading delete/update are now wrapped in a transaction
+ for atomicity
- Fix regression where SQL files with comments were not
handled properly by ::Schema::Versioned.
- Fix regression on not properly throwing when $obj->relationship
# be handling this anyway. Assuming we have joins we probably actually
# *could* do them, but I'd rather not.
- my $ret = $self->next::method(@rest);
-
my $source = $self->result_source;
my %rels = map { $_ => $source->relationship_info($_) } $source->relationships;
my @cascade = grep { $rels{$_}{attrs}{cascade_delete} } keys %rels;
- foreach my $rel (@cascade) {
- $self->search_related($rel)->delete_all;
+
+ if (@cascade) {
+ my $guard = $source->schema->txn_scope_guard;
+
+ my $ret = $self->next::method(@rest);
+
+ foreach my $rel (@cascade) {
+ $self->search_related($rel)->delete_all;
+ }
+
+ $guard->commit;
+ return $ret;
}
- return $ret;
+
+ $self->next::method(@rest);
}
sub update {
return $self->next::method(@rest) unless ref $self;
# Because update cascades on a class *really* don't make sense!
- my $ret = $self->next::method(@rest);
-
my $source = $self->result_source;
my %rels = map { $_ => $source->relationship_info($_) } $source->relationships;
my @cascade = grep { $rels{$_}{attrs}{cascade_update} } keys %rels;
- foreach my $rel (@cascade) {
- next if (
- $rels{$rel}{attrs}{accessor}
- &&
- $rels{$rel}{attrs}{accessor} eq 'single'
- &&
- !exists($self->{_relationship_data}{$rel})
- );
- $_->update for grep defined, $self->$rel;
+
+ if (@cascade) {
+ my $guard = $source->schema->txn_scope_guard;
+
+ my $ret = $self->next::method(@rest);
+
+ foreach my $rel (@cascade) {
+ next if (
+ $rels{$rel}{attrs}{accessor}
+ &&
+ $rels{$rel}{attrs}{accessor} eq 'single'
+ &&
+ !exists($self->{_relationship_data}{$rel})
+ );
+ $_->update for grep defined, $self->$rel;
+ }
+
+ $guard->commit;
+ return $ret;
}
- return $ret;
+
+ $self->next::method(@rest);
}
1;
no warnings 'redefine';
no strict 'refs';
- # die in rollback, but maintain sanity for further tests ...
+ # die in rollback
local *{"DBIx::Class::Storage::DBI::SQLite::txn_rollback"} = sub{
my $storage = shift;
- $storage->{transaction_depth}--;
die 'FAILED';
};
$schema->storage->_dbh->rollback;
}
+# reset schema object (the txn_rollback meddling screws it up)
+$schema = DBICTest->init_schema();
+
# Test nested failed txn_do()
{
is( $schema->storage->{transaction_depth}, 0, 'txn depth starts at 0');