From 555533313d1c78fb2a781988c965e9f21bd203cd Mon Sep 17 00:00:00 2001 From: Andre Konstantinov Date: Fri, 3 Mar 2023 10:39:54 -0500 Subject: [PATCH] Replace after_* callbacks with after_commit with on: --- lib/elastic_record/model/callbacks.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/elastic_record/model/callbacks.rb b/lib/elastic_record/model/callbacks.rb index 49d15ea..2a34725 100644 --- a/lib/elastic_record/model/callbacks.rb +++ b/lib/elastic_record/model/callbacks.rb @@ -2,12 +2,12 @@ module ElasticRecord module Model module Callbacks def self.included(base) - return unless base.respond_to?(:after_save) && base.respond_to?(:after_destroy) + return unless base.respond_to?(:after_commit) base.class_eval do - after_create :index_to_elasticsearch - after_update :update_index_document, if: -> { respond_to?(:saved_changes?) ? saved_changes? : changed? } - after_destroy :delete_index_document + after_commit :index_to_elasticsearch, on: :create + after_commit :update_index_document, on: :update, if: -> { respond_to?(:saved_changes?) ? saved_changes? : changed? } + after_commit :delete_index_document, on: :destroy end end