From 5f401a7b0421a05b60e3a2a24fa6b97b931711c1 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 26 Aug 2014 16:24:44 +0200 Subject: [PATCH] Improved order of callback for destroy (delete references first). --- app/models/application_model.rb | 4 ++-- app/models/recent_view.rb | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/models/application_model.rb b/app/models/application_model.rb index 6fd36e31e..359d268d8 100644 --- a/app/models/application_model.rb +++ b/app/models/application_model.rb @@ -21,7 +21,7 @@ class ApplicationModel < ActiveRecord::Base after_create :activity_stream_create after_update :activity_stream_update - after_destroy :activity_stream_destroy + before_destroy :activity_stream_destroy after_create :history_create after_update :history_update @@ -31,7 +31,7 @@ class ApplicationModel < ActiveRecord::Base after_update :search_index_update after_destroy :search_index_destroy - after_destroy :recent_view_destroy + before_destroy :recent_view_destroy # create instance accessor class << self diff --git a/app/models/recent_view.rb b/app/models/recent_view.rb index 5bd6193b8..945308202 100644 --- a/app/models/recent_view.rb +++ b/app/models/recent_view.rb @@ -22,9 +22,10 @@ class RecentView < ApplicationModel end def self.log_destroy( requested_object, requested_object_id ) + return if requested_object == 'RecentView' RecentView.where( :recent_view_object_id => ObjectLookup.by_name( requested_object ) ). - where( :o_id => requested_object_id ). - destroy_all + where( :o_id => requested_object_id ). + destroy_all end def self.user_log_destroy( user )