I'm having some problems with acts_as_versioned. All my foo_versions have the same version id. Description by example:
ruby script/console
Loading development environment.
p = Product.find_by_id 1
[...]
p.versions.size
=> 6
p.versions.each { |version|
?> puts version.id
}
1 2 3 4 5 6 [...]
p.find_version 1
=> #<Item::Version:0x8ed788c @attributes={"item_id"=>"1", "name"=>"", "visible"=>"1", "brand_id"=>"1", "updated_at"=>"2006-11-24 16:34:01", "code"=>"", "title"=>"", "versioned_type"=>"Product", "creator_id"=>"1", "id"=>"1", "version"=>"1", "heading"=>"", "description"=>"", "updater_id"=>"1", "created_at"=>"2006-11-24 16:34:01"}> [some content removed]
p.find_version 2
=> nil
p.find_version 3
=> nil
p.find_version 4
=> nil
p.find_version 5
=> nil
p.find_version 6
=> nil
Looking at the Database:
select version from item_versions;
1 1 1 1 1 1
Is this because I'm using inheritance?
The structure is:
Element (editable, versionable, etc) > Item (purchaseable) > Product (single item, no special discounts, etc)
I've tried to move as much of the logic for each layer to the bottom of the heap. Thus my Element class looks like this:
cat app/models/element.rb
class Element < ActiveRecord::Base public self.abstract_class = true
has_one :creator, :class_name => 'Editor', :foreign_key => :id has_one :updater, :class_name => 'Editor', :foreign_key => :id
validates_presence_of :created_at, :on => :update validates_presence_of :updated_at, :on => :update validates_inclusion_of :visible, :in => 0..1 end
How can I nail down the issue? My guess is that acts_as_versioned is thinking I'm always making a version 1 as it is looking at Item or Product where it shouldn't be. Any help or criticisms of the approach I have taken above appreciated. This is mostly a proof of concept for a possible piece of further development at the moment.
Thanks! Dominic