lib/neo4j/shared/callbacks.rb in neo4j-4.0.0 vs lib/neo4j/shared/callbacks.rb in neo4j-4.1.0

- old
+ new

@@ -7,16 +7,24 @@ include ActiveModel::Callbacks end included do include ActiveModel::Validations::Callbacks - define_model_callbacks :initialize, :find, :only => :after + define_model_callbacks :initialize, :find, only: :after define_model_callbacks :save, :create, :update, :destroy end def destroy #:nodoc: + tx = Neo4j::Transaction.new run_callbacks(:destroy) { super } + rescue + @_deleted = false + @attributes = @attributes.dup + tx.mark_failed + raise + ensure + tx.close if tx end def touch(*) #:nodoc: run_callbacks(:touch) { super } end @@ -26,15 +34,18 @@ def create_or_update #:nodoc: run_callbacks(:save) { super } end def create_model #:nodoc: - run_callbacks(:create) { super } + Neo4j::Transaction.run do + run_callbacks(:create) { super } + end end def update_model(*) #:nodoc: - run_callbacks(:update) { super } + Neo4j::Transaction.run do + run_callbacks(:update) { super } + end end end - end end