<?xml version="1.0" encoding="UTF-8"?>
<wiki>
  <body>&lt;p&gt;Issue 3: making version_fu play well with acts_as_deletable: &lt;a href=&quot;http://wiki.github.com/ajh/acts_as_soft_deletable&quot;&gt;http://wiki.github.com/ajh/acts_as_soft_deletable&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Issue 2: wrong values for text/blob moved over to versioned table&lt;/p&gt;
&lt;p&gt;Issue 1: undefined method `version=&amp;#8217;  (resolved)&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Issue 3:&lt;/p&gt;
&lt;p&gt;When both version_fu and acts_as_deletable are operating on a class, deletions followed by restores lose the version history.  I am trying to make the version class itself deletable, but not much luck so far.  I have modified version_fu.rb as follows:&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
&lt;code&gt;&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;Versioned Model&lt;br /&gt;
      const_set(versioned_class_name, Class.new(ActiveRecord::Base)).class_eval do&lt;br /&gt;
        acts_as_soft_deletable # need deleted_statistic_type_versions table&lt;/li&gt;
	&lt;li&gt;find first version before the given version&lt;br /&gt;
        def self.before(version)&lt;br /&gt;
          find :first, :order =&amp;gt; &amp;#8216;version desc&amp;#8217;,&lt;br /&gt;
            :conditions =&amp;gt; [&amp;#8220;#{original_class.versioned_foreign_key} = ? and version &amp;lt; ?&amp;#8221;, version.send(original_class.versioned_foreign_key), version.version]&lt;br /&gt;
        end&lt;br /&gt;
&lt;/code&gt;&lt;br /&gt;
&lt;/pre&gt;&lt;br /&gt;
and this works to the extent that versions are added to the deleted_statistic_type_versions table.  However I now need undestroy! to restore the versions as well as the orginal model.  To that end I have modified acts_as_soft_deletable as follows:&lt;/li&gt;
&lt;/ol&gt;
module InstanceMethods
&lt;ol&gt;
	&lt;li&gt;Restore the model from deleted status. Will destroy the deleted&lt;/li&gt;
	&lt;li&gt;record and recreate the live record. This is done in a transaction&lt;/li&gt;
	&lt;li&gt;and will rollback if problems occur.&lt;br /&gt;
          def undestroy!&lt;br /&gt;
            self.class.transaction do&lt;/li&gt;
	&lt;li&gt;check for any versions and undelete those too&lt;br /&gt;
              deleted_versions = self.class.live_class::Version::Deleted.find_all_by_statistic_type_id(self.id)&lt;br /&gt;
              deleted_versions.each do |deleted|&lt;br /&gt;
                deleted.undestroy!&lt;br /&gt;
              end&lt;/li&gt;
	&lt;li&gt;create instance in version table&lt;br /&gt;
              model = self.class.live_class.new&lt;br /&gt;
              self.attributes.reject{|k,v| k == &amp;#8217;deleted_at&amp;#8217;}.keys.each do |key|&lt;br /&gt;
                model.send(&amp;#8220;#{key}=&amp;#8221;, self.send(key))&lt;br /&gt;
              end&lt;br /&gt;
              model.save!&lt;/li&gt;
&lt;/ol&gt;
self.destroy
end
true
end
end
&lt;p&gt;and the query to grab all the deleted versions runs fine from the console:&lt;/p&gt;
&lt;p&gt;self.class.live_class::Version::Deleted.find_all_by_statistic_type_id(self.id)&lt;/p&gt;
&lt;p&gt;However I get the following error when I try to undestroy from a unit test:&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
&lt;code&gt;
  1) Error:
test_versioning(StatisticTypeTest):
ArgumentError: StatisticType is not missing constant Version!
    /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:253:in `load_missing_constant'
    /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:484:in `const_missing'
    /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:486:in `send'
    /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:486:in `const_missing'
    /Users/samueljoseph/Code/eclipse-workspace/iknow_reporting-fresh/vendor/plugins/acts_as_soft_deletable/lib/acts_as_soft_deletable.rb:118:in `undestroy!'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in `transaction'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/transactions.rb:79:in `transaction'
    /Users/samueljoseph/Code/eclipse-workspace/iknow_reporting-fresh/vendor/plugins/acts_as_soft_deletable/lib/acts_as_soft_deletable.rb:116:in `undestroy!'
    /Users/samueljoseph/Code/eclipse-workspace/iknow_reporting-fresh/vendor/plugins/acts_as_soft_deletable/lib/acts_as_soft_deletable.rb:120:in `undestroy!'
    /Users/samueljoseph/Code/eclipse-workspace/iknow_reporting-fresh/vendor/plugins/acts_as_soft_deletable/lib/acts_as_soft_deletable.rb:119:in `each'
    /Users/samueljoseph/Code/eclipse-workspace/iknow_reporting-fresh/vendor/plugins/acts_as_soft_deletable/lib/acts_as_soft_deletable.rb:119:in `undestroy!'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in `transaction'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/transactions.rb:79:in `transaction'
    /Users/samueljoseph/Code/eclipse-workspace/iknow_reporting-fresh/vendor/plugins/acts_as_soft_deletable/lib/acts_as_soft_deletable.rb:116:in `undestroy!'
    test/unit/statistic_type_test.rb:45:in `test_versioning'
    /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/testing/setup_and_teardown.rb:67:in `__send__'
    /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/testing/setup_and_teardown.rb:67:in `run'&lt;/p&gt;
&lt;p&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#8217;ll also add this to the acts_as_soft_deletable wiki as well.  Why github doesn&amp;#8217;t have built in forums for projects I have no idea &amp;#8230;&lt;/p&gt;
&lt;p&gt;I&amp;#8217;ve now got round this problem by using the following code in acts_as_soft_deletable:&lt;/p&gt;
module InstanceMethods
&lt;ol&gt;
	&lt;li&gt;Restore the model from deleted status. Will destroy the deleted&lt;/li&gt;
	&lt;li&gt;record and recreate the live record. This is done in a transaction&lt;/li&gt;
	&lt;li&gt;and will rollback if problems occur.&lt;br /&gt;
          def undestroy!&lt;br /&gt;
            self.class.transaction do&lt;/li&gt;
	&lt;li&gt;check for any versions and undelete those too&lt;br /&gt;
              if self.class.live_class.respond_to?(:versioned_class_name)&lt;br /&gt;
                deleted_versions = self.class.live_class::Version::Deleted.find_all_by_statistic_type_id(self.id)&lt;br /&gt;
                deleted_versions.each do |deleted|&lt;br /&gt;
                  deleted.undestroy!&lt;br /&gt;
                end&lt;br /&gt;
              end&lt;/li&gt;
	&lt;li&gt;create instance in version table&lt;br /&gt;
              model = self.class.live_class.new&lt;br /&gt;
              self.attributes.reject{|k,v| k == &amp;#8217;deleted_at&amp;#8217;}.keys.each do |key|&lt;br /&gt;
                model.send(&amp;#8220;#{key}=&amp;#8221;, self.send(key))&lt;br /&gt;
              end&lt;br /&gt;
              model.save!&lt;/li&gt;
&lt;/ol&gt;
self.destroy
end
true
end
end
&lt;p&gt;This if statement &amp;#8220;if self.class.live_class.respond_to?(:versioned_class_name)&amp;#8221; makes sure that we don&amp;#8217;t try and look for versions of versions.  Now I have the versions being undeleted, but unfortunately when the live_class is recreated by acts_as_soft_deletable it also fires off version_fu, which adds a new row to the versions table which is now unecessary.  Trying to switch that off now &amp;#8230; Aha, I think I may have cracked it:&lt;/p&gt;
module InstanceMethods
&lt;ol&gt;
	&lt;li&gt;Restore the model from deleted status. Will destroy the deleted&lt;/li&gt;
	&lt;li&gt;record and recreate the live record. This is done in a transaction&lt;/li&gt;
	&lt;li&gt;and will rollback if problems occur.&lt;br /&gt;
          def undestroy!&lt;br /&gt;
            self.class.transaction do&lt;/li&gt;
	&lt;li&gt;check for any versions and undelete those too&lt;br /&gt;
              if self.class.live_class.respond_to?(:versioned_class_name)&lt;br /&gt;
                deleted_versions = self.class.live_class::Version::Deleted.find_all_by_statistic_type_id(self.id)&lt;br /&gt;
                deleted_versions.each do |deleted|&lt;br /&gt;
                  deleted.undestroy!&lt;br /&gt;
                end&lt;br /&gt;
              end&lt;/li&gt;
	&lt;li&gt;create instance in version table&lt;br /&gt;
              model = self.class.live_class.new&lt;br /&gt;
              self.attributes.reject{|k,v| k == &amp;#8217;deleted_at&amp;#8217;}.keys.each do |key|&lt;br /&gt;
                model.send(&amp;#8220;#{key}=&amp;#8221;, self.send(key))&lt;br /&gt;
              end&lt;br /&gt;
              model.restoring_from_delete = true if self.class.live_class.respond_to?(:restoring_from_delete)&lt;br /&gt;
              model.save!&lt;/li&gt;
&lt;/ol&gt;
self.destroy
end
true
end
end
&lt;p&gt;on the acts_as_soft_deletable side combined with&lt;/p&gt;
def create_new_version?
if self.restoring_from_delete
self.restoring_from_delete = false
return false
end
&lt;ol&gt;
	&lt;li&gt;Any versioned column changed?&lt;/li&gt;
	&lt;li&gt;don&amp;#8217;t create new version if being called from acts_as_soft_deletable&lt;br /&gt;
      self.class.versioned_columns.detect {|a| &lt;i&gt;send&lt;/i&gt; &amp;#8220;#{a}_changed?&amp;#8221;}&lt;br /&gt;
    end&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;on the version_fu side along with:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;
      cattr_accessor :versioned_class_name, :versioned_foreign_key, :versioned_table_name,
                     :version_column, :versioned_columns, :restoring_from_delete

      self.versioned_class_name         = options[:class_name]  || 'Version'
      self.versioned_foreign_key        = options[:foreign_key] || self.to_s.foreign_key
      self.versioned_table_name         = options[:table_name]  || &quot;#{table_name_prefix}#{base_class.name.demodulize.underscore}_versions#{table_name_suffix}&quot;
      self.version_column               = options[:version_column]    || 'version'
      self.restoring_from_delete        = false
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;Seems to do the trick.  I have some of my own unit-tests but not sure how to integrate across the two projects.  Any tips on how to submit code back so that these two great plugins will play nicely together will be very much appreciated.&lt;/p&gt;
&lt;hr /&gt;
&lt;p&gt;Issue 2:&lt;/p&gt;
&lt;p&gt;the text field in the table created by the following:&lt;/p&gt;
def self.up
create_table :statistic_type_versions do |t|
t.integer :statistic_type_id, :statistic_category_id
t.string  :name, :time_filter, :unit
t.text    :sql
t.timestamps
end
add_column :statistic_types, :version, :integer, :default=&amp;gt;1
end
&lt;p&gt;appears to have the data from the new version rather than the old version in it.  The old data appears to be lost.  The text/blob field may also just be nil as shown in the example below:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;
&amp;gt;&amp;gt; type = StatisticType.new  
=&amp;gt; #&amp;lt;StatisticType id: nil, name: &quot;&quot;, time_filter: &quot;&quot;, unit: &quot;&quot;, sql: nil, statistic_category_id: nil, version: 1&amp;gt;  
&amp;gt;&amp;gt; type.name = 'original_name'  
=&amp;gt; &quot;original_name&quot;  
&amp;gt;&amp;gt; type.sql = 'original_sql'  
=&amp;gt; &quot;original_sql&quot;  
&amp;gt;&amp;gt; type.save  
=&amp;gt; true  
&amp;gt;&amp;gt; type.name  
=&amp;gt; &quot;original_name&quot;  
&amp;gt;&amp;gt; type.sql  
=&amp;gt; &quot;original_sql&quot;  
&amp;gt;&amp;gt; type.name = 'new_name'  
=&amp;gt; &quot;new_name&quot;  
&amp;gt;&amp;gt; type.sql = 'new_sql'  
=&amp;gt; &quot;new_sql&quot;  
&amp;gt;&amp;gt; type.save  
=&amp;gt; true  
&amp;gt;&amp;gt; type.name  
=&amp;gt; &quot;new_name&quot;  
&amp;gt;&amp;gt; type.sql  
=&amp;gt; &quot;new_sql&quot;  
&amp;gt;&amp;gt; type.id  
=&amp;gt; 5  
&amp;gt;&amp;gt; versioned_type = StatisticType::Version.find(:first, :conditions =&amp;gt; 'statistic_type_id = 5')  
=&amp;gt; #&amp;lt;StatisticType::Version id: 7, statistic_type_id: 5, statistic_category_id: nil, version: 1, name: &quot;original_name&quot;, time_filter: &quot;&quot;, unit: &quot;&quot;, sql: nil, created_at: &quot;2008-10-31 15:34:15&quot;, updated_at: &quot;2008-10-31 15:34:15&quot;&amp;gt;  
&amp;gt;&amp;gt; versioned_type.name  
=&amp;gt; &quot;original_name&quot;  
&amp;gt;&amp;gt; versioned_type.sql  
=&amp;gt; nil  
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;Here&amp;#8217;s rails log of the &lt;span class=&quot;caps&quot;&gt;SQL&lt;/span&gt; commands generated by version_fu in the above example&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;
SQL (0.000213)   SET NAMES 'utf8'
  SQL (0.000118)   SET SQL_AUTO_IS_NULL=0
  StatisticType::Version Columns (0.002405)   SHOW FIELDS FROM `statistic_type_versions`
  StatisticType Columns (0.001584)   SHOW FIELDS FROM `statistic_types`
  SQL (0.000295)   BEGIN
  StatisticType Create (0.000241)   INSERT INTO `statistic_types` (`name`, `statistic_category_id`, `sql`, `unit`, `version`, `time_filter`) VALUES('original_name', NULL, 'original_sql', '', 1, '')
  StatisticType::Version Load (0.000273)   SELECT * FROM `statistic_type_versions` WHERE (`statistic_type_versions`.statistic_type_id = NULL) 
  StatisticType::Version Create (0.000181)   INSERT INTO `statistic_type_versions` (`name`, `updated_at`, `statistic_category_id`, `sql`, `unit`, `statistic_type_id`, `version`, `time_filter`, `created_at`) VALUES('original_name', '2008-10-31 16:08:36', NULL, 'original_sql', '', 6, 1, '', '2008-10-31 16:08:36')
  SQL (0.053981)   COMMIT
  SQL (0.000294)   BEGIN
  StatisticType Update (0.000285)   UPDATE `statistic_types` SET `sql` = 'new_sql', `version` = 2, `name` = 'new_name' WHERE `id` = 6
  StatisticType::Version Create (0.000196)   INSERT INTO `statistic_type_versions` (`name`, `updated_at`, `statistic_category_id`, `sql`, `unit`, `statistic_type_id`, `version`, `time_filter`, `created_at`) VALUES('new_name', '2008-10-31 16:09:25', NULL, 'new_sql', '', 6, 2, '', '2008-10-31 16:09:25')
  SQL (0.000587)   COMMIT
  StatisticType::Version Load (0.001143)   SELECT * FROM `statistic_type_versions` WHERE (statistic_type_id = 6) LIMIT 1
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;In my test database it seems like saving causes two rows to be added to the version table, one for the old version and another for the new version (which doesn&amp;#8217;t seem wonderfully dry, given some of that information is in the original table), but in my production database there is only ever one row added to the version table after a save &amp;#8230;&lt;/p&gt;
&lt;p&gt;Any ideas what might be causing this problem?&lt;/p&gt;
&lt;p&gt;Many thanks in advance&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Response&lt;/strong&gt; Instead of&lt;/p&gt;
&lt;pre&gt;StatisticType::Version.find(:first, :conditions =&amp;gt; 'statistic_type_id = 5')&lt;/pre&gt;
&lt;p&gt;try type.versions&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Follow Up&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Unfortunately that doesn&amp;#8217;t seem to help, e.g.&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;
&amp;gt;&amp;gt; type = StatisticType.find(51)
=&amp;gt; #&amp;lt;StatisticType id: 51, name: &quot;registered users&quot;, time_filter: &quot;RollingDayFilter.new(DayFilter.new(time_point).prev...&quot;, unit: &quot;&quot;, 
sql: &quot;\&quot;SELECT COUNT(*) AS total_registered_users\nFROM \#{A...&quot;, statistic_category_id: 11, version: 1&amp;gt;
&amp;gt;&amp;gt; type.sql = 'new stuff'
=&amp;gt; &quot;new stuff&quot;
&amp;gt;&amp;gt; type.save
=&amp;gt; true
&amp;gt;&amp;gt; type.versions
=&amp;gt; [#&amp;lt;StatisticType::Version id: 8, statistic_type_id: 51, statistic_category_id: 11, version: 2, name: &quot;registered users&quot;, 
time_filter: &quot;RollingDayFilter.new(DayFilter.new(time_point).prev...&quot;, unit: &quot;&quot;, sql: &quot;new stuff&quot;, created_at: &quot;2008-11-01 02:26:23&quot;, 
updated_at: &quot;2008-11-01 02:26:23&quot;&amp;gt;]
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;Notice how there is only one element in the type.versions array, and it has the sql field set to &amp;#8220;new stuff&amp;#8221;.  The old version has disappeared.&lt;/p&gt;
&lt;p&gt;Here is the rails log for the above:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;
  StatisticType Load (0.000593)   SELECT * FROM `statistic_types` WHERE (`statistic_types`.`id` = 51) 
  SQL (0.000272)   BEGIN
  StatisticType Update (0.000390)   UPDATE `statistic_types` SET `sql` = 'new stuff', `version` = 2 WHERE `id` = 51
  StatisticType::Version Create (0.000360)   INSERT INTO `statistic_type_versions` (`name`, `updated_at`, `statistic_category_id`, 
`sql`, `unit`, `statistic_type_id`, `version`, `time_filter`, `created_at`) VALUES('registered users', '2008-11-01 02:26:23', 
11, 'new stuff', '', 51, 2, 'RollingDayFilter.new(DayFilter.new(time_point).prev.raw_time)', '2008-11-01 02:26:23')
  SQL (0.001074)   COMMIT
StatisticType::Version Load (0.000570)   SELECT * FROM `statistic_type_versions` WHERE (`statistic_type_versions`.statistic_type_id = 51)
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;It seems that only one entry is inserted into the versions table, it is version 2 and it has &amp;#8220;new stuff&amp;#8221; in the sql field, i.e version 1 has been lost &amp;#8230;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Well it seems that the problem is that version_fu assumes that the model has been created through the version_fu framework, and is assuming that there will already be an entry in the version table for the first version of the model.  In my case I added version_fu to an existing legacy table, which is why I ran into this problem.  My hacky solution is go through the legacy data and dump copies of first versions into the version table to ensure that things don&amp;#8217;t get deleted accidentally.&lt;/p&gt;
&lt;p&gt;However it does seem a little unDRY to be storing the version 1 in the versions table from the get go.  Was there some difficulty that meant that this was much easier than the previous acts_as_versioned system which only dumped something in the versions table after version 2 appeared?&lt;br /&gt;
&lt;del&gt;-&lt;/del&gt;&amp;#8212;&lt;/p&gt;
&lt;p&gt;Issue 1:&lt;/p&gt;
&lt;p&gt;I&amp;#8217;m getting the following error when trying to save a versioned model in Rails 2.1.1:&lt;br /&gt;
My model&lt;/p&gt;
&lt;p&gt;class StatisticType &amp;lt; ActiveRecord::Base&lt;br /&gt;
  has_many :statistic_summaries&lt;br /&gt;
  version_fu&lt;br /&gt;
end&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;gt; type = StatisticType.find(1)&lt;br /&gt;
&amp;gt;&amp;gt; type.name = &amp;#8216;bob&amp;#8217;&lt;br /&gt;
=&amp;gt; &amp;#8220;bob&amp;#8221;&lt;br /&gt;
&amp;gt;&amp;gt; type.save&lt;br /&gt;
NoMethodError: undefined method `version=&amp;#8217; for #&lt;StatisticType::Version:0x244c3a0&gt;&lt;br /&gt;
	from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/attribute_methods.rb:251:in `method_missing&amp;#8217;&lt;br /&gt;
	from /Users/samueljoseph/Code/eclipse-workspace/iknow_reporting/vendor/plugins/version_fu/lib/version_fu.rb:101:in `instatiate_revision&amp;#8217;&lt;br /&gt;
	from /Users/samueljoseph/Code/eclipse-workspace/iknow_reporting/vendor/plugins/version_fu/lib/version_fu.rb:85:in `check_for_new_version&amp;#8217;&lt;br /&gt;
	from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/callbacks.rb:173:in `send&amp;#8217;&lt;br /&gt;
	from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/callbacks.rb:173:in `evaluate_method&amp;#8217;&lt;br /&gt;
	from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/callbacks.rb:161:in `call&amp;#8217;&lt;br /&gt;
	from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/callbacks.rb:93:in `run&amp;#8217;&lt;br /&gt;
	from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/callbacks.rb:92:in `each&amp;#8217;&lt;br /&gt;
	from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/callbacks.rb:92:in `send&amp;#8217;&lt;br /&gt;
	from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/callbacks.rb:92:in `run&amp;#8217;&lt;br /&gt;
	from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/callbacks.rb:272:in `run_callbacks&amp;#8217;&lt;br /&gt;
	from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/callbacks.rb:298:in `callback&amp;#8217;&lt;br /&gt;
	from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/callbacks.rb:206:in `create_or_update&amp;#8217;&lt;br /&gt;
	from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/base.rb:2211:in `save_without_validation&amp;#8217;&lt;br /&gt;
	from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/validations.rb:911:in `save_without_dirty&amp;#8217;&lt;br /&gt;
	from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/dirty.rb:75:in `save_without_transactions&amp;#8217;&lt;br /&gt;
	from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/transactions.rb:106:in `save&amp;#8217;&lt;br /&gt;
	from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:66:in `transaction&amp;#8217;&lt;br /&gt;
	from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/transactions.rb:79:in `transaction&amp;#8217;&lt;br /&gt;
	from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/transactions.rb:98:in `transaction&amp;#8217;&lt;br /&gt;
	from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/transactions.rb:106:in `save&amp;#8217;&lt;br /&gt;
	from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/transactions.rb:118:in `rollback_active_record_state!&amp;#8217;&lt;br /&gt;
	from /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.1/lib/active_record/transactions.rb:106:in `save&amp;#8217;&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s the migration I used to prepare things (I checked in the database to make sure the changes are there):&lt;/p&gt;
&lt;p&gt;class AddStatisticTypeVersioning &amp;lt; ActiveRecord::Migration&lt;/p&gt;
def self.up
create_table :statistic_type_versions do |t|
t.integer :statistic_type_id, :statistic_category_id
t.string  :name, :time_filter, :unit
t.text    :sql
t.timestamps
end
add_column :statistic_types, :version, :integer, :default=&amp;gt;1
end

def self.down
remove_column :statistic_types, :version
drop_table :statistic_type_versions
end

&lt;p&gt;end&lt;/p&gt;
&lt;p&gt;Am I making some simple mistake?&lt;/p&gt;
&lt;p&gt;Many thanks in advance&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt; You need a version(int) column in the statistic_type_versions table&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Response&lt;/strong&gt; Many thanks &amp;#8211; I added that but I still seem to get the same error, i.e. undefined method `version=&amp;#8217; for #&lt;StatisticType::Version:0x244c3a0&gt; which is very odd &amp;#8230; is the usage of version_fu close to identical to that of acts_as_versioned?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Answer&lt;/strong&gt; ah, I hadn&amp;#8217;t re-created the test database off the new structure &amp;#8211; working now &amp;#8230;&lt;/p&gt;
&lt;hr /&gt;
</body>
  <created-at type="datetime">2008-10-21T12:56:16-07:00</created-at>
  <id type="integer">70375</id>
  <permalink>troubleshooting</permalink>
  <repository-id type="integer">12955</repository-id>
  <title>TroubleShooting</title>
  <updated-at type="datetime">2009-03-10T17:30:26-07:00</updated-at>
  <user-id type="integer">30216</user-id>
</wiki>
