ruby on rails - ActiveRecord - Callback after all transactions have finished being commited to db -


here model. want set_variations method run when transactions have finished being committed db.. current after_commit, runs method after each commit.. thinking of maybe counter of sort, don't know how many new products added until after process finishes.. how this?

class product < activerecord::base   belongs_to :merchant    validates :sellersku, uniqueness: true   validates :asin, uniqueness: true    include send    before_save     :split_off    after_commit    :set_variations     def split_off     @merchant = self.merchant_id     self.five_of_asin = self.asin[0,5]     self.twenty_of_title = self.title[0,20]   end    def set_variations     binding.pry     product.where(merchant_id: @merchant).find_each |merch|       variations = merch.group(:twenty_of_title).count     end   end end 


Comments