Further clean up PostrgreSQL array types examples
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Pg.pm
index 7c20330..a67bc2f 100644 (file)
@@ -6,6 +6,7 @@ use warnings;
 use base qw/DBIx::Class::Storage::DBI/;
 
 use Scope::Guard ();
+use Scalar::Util 'weaken';
 use Context::Preserve 'preserve_context';
 use DBIx::Class::Carp;
 use Try::Tiny;
@@ -30,11 +31,13 @@ sub with_deferred_fk_checks {
 
   $self->_do_query('SET CONSTRAINTS ALL DEFERRED');
 
-  my $sg = Scope::Guard->new(sub {
-    $self->_do_query('SET CONSTRAINTS ALL IMMEDIATE');
-  });
-
-  return preserve_context { $sub->() } after => sub { $txn_scope_guard->commit };
+  weaken($self);
+  return preserve_context {
+    my $sg = Scope::Guard->new(sub {
+      $self->_do_query('SET CONSTRAINTS ALL IMMEDIATE');
+    });
+    $sub->()
+  } after => sub { $txn_scope_guard->commit };
 }
 
 # only used when INSERT ... RETURNING is disabled