From 531653596d342489e80ef6a7a38edaadb1ec2dbf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Felix=20Sch=C3=A4fer?= <f.schaefer@finn.de>
Date: Fri, 29 Jul 2011 15:12:06 +0200
Subject: [PATCH] Touch journaled objects on journal creation only. #543

---
 app/models/journal.rb | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/app/models/journal.rb b/app/models/journal.rb
index 0b807fb2d..c7818d765 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -28,9 +28,12 @@ class Journal < ActiveRecord::Base
   # subclasses will be given an actual class name when they are created by aaj
   #
   #  e.g. IssueJournal will get :class_name => 'Issue'
-  belongs_to :journaled, :touch => true, :class_name => 'Journal'
+  belongs_to :journaled, :class_name => 'Journal'
   belongs_to :user
 
+  # "touch" the journaled object on creation
+  after_create :touch_journaled_after_creation
+
   # ActiveRecord::Base#changes is an existing method, so before serializing the +changes+ column,
   # the existing +changes+ method is undefined. The overridden +changes+ method pertained to
   # dirty attributes, but will not affect the partial updates functionality as that's based on
@@ -38,6 +41,10 @@ class Journal < ActiveRecord::Base
   # undef_method :changes
   serialize :changes, Hash
 
+  def touch_journaled_after_creation
+    journaled.touch
+  end
+
   # In conjunction with the included Comparable module, allows comparison of journal records
   # based on their corresponding version numbers, creation timestamps and IDs.
   def <=>(other)
-- 
GitLab