From b52d2b2238f1cea95790746d47f1e3b08516fbb4 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Thu, 16 Jun 2011 10:43:04 -0700 Subject: [PATCH 1/2] [#467] Fix uninitialized constant Journal::Journaled error Was due to Journals touching the parent record but the Journal not having it's STI class correct during the type update. --- db/migrate/20100714111651_generalize_journals.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/db/migrate/20100714111651_generalize_journals.rb b/db/migrate/20100714111651_generalize_journals.rb index 2dbea59e..d4e20c83 100644 --- a/db/migrate/20100714111651_generalize_journals.rb +++ b/db/migrate/20100714111651_generalize_journals.rb @@ -35,10 +35,14 @@ class GeneralizeJournals < ActiveRecord::Migration Journal.all.group_by(&:journaled_id).each_pair do |id, journals| journals.sort_by(&:created_at).each_with_index do |j, idx| - j.update_attribute(:type, "#{j.journalized_type}Journal") - j.update_attribute(:version, idx + 1) + # Recast the basic Journal into it's STI journalized class so callbacks work (#467) + klass_name = "#{j.journalized_type}Journal" + j = j.becomes(klass_name.constantize) + j.type = klass_name + j.version = idx + 1 # FIXME: Find some way to choose the right activity here - j.update_attribute(:activity_type, j.journalized_type.constantize.activity_provider_options.keys.first) + j.activity_type = j.journalized_type.constantize.activity_provider_options.keys.first + j.save(false) end end From 47c7e0774af50d72a178fbf34e016bfa4b35a8e0 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Fri, 17 Jun 2011 09:41:14 -0700 Subject: [PATCH 2/2] [#467] Fix bug with Journal subclasses having caches columns --- db/migrate/20100714111651_generalize_journals.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/db/migrate/20100714111651_generalize_journals.rb b/db/migrate/20100714111651_generalize_journals.rb index d4e20c83..b017ea25 100644 --- a/db/migrate/20100714111651_generalize_journals.rb +++ b/db/migrate/20100714111651_generalize_journals.rb @@ -50,6 +50,12 @@ class GeneralizeJournals < ActiveRecord::Migration t.remove :journalized_type end + # Reset class and subclasses, otherwise they will try to save using older attributes + Journal.reset_column_information + Journal.send(:subclasses).each do |klass| + klass.reset_column_information if klass.respond_to?(:reset_column_information) + end + # Build initial journals for all activity providers providers = Redmine::Activity.providers.collect {|k, v| v.collect(&:constantize) }.flatten.compact.uniq providers.each do |p|