Callback for rails 4 delete_all -


i have unreadentry model , using after_commit callback send notification pusher service. problem event fires fine when adding records when delete_all sent on model, neither: after_commit, after_destroy fired.

how can add catch delete_all , add callback it?

class unreadentry < activerecord::base   belongs_to :user   belongs_to :feed   belongs_to :entry    after_commit :send_pusher_notification, if: pusher_enabled    validates_uniqueness_of :user_id, scope: :entry_id    def self.create_from_owners(user, entry)     create(user_id: user.id, feed_id: entry.feed_id, entry_id: entry.id, published: entry.published, entry_created_at: entry.created_at)   end    def self.sort_preference(sort)     if sort == 'asc'       order("published asc")     else       order("published desc")     end   end    def send_pusher_notification(user = nil, = 'unreadentry#callback')     if user.nil?       unread_count = unreadentry.where(user_id: self.user_id).count     else       unread_count = unreadentry.where(user_id: user.id).count     end     pusher['rssapp'].trigger('unread_count', {       message: unread_count     })     end  end 

simple - don't use delete_all. delete_all , update_all designed query database directly, bypassing activerecord model logic - including validations , callbacks. if want callbacks, call destroy on each model instance individually.

my_collection.each(&:destroy) 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -