Permalink
Browse files

bugfix

  • Loading branch information...
tomasc committed Dec 27, 2010
1 parent cb5b4d9 commit 691c510cdc35d2bc057bd477800900c905f230ce
Showing with 7 additions and 3 deletions.
  1. +1 −1 lib/mongo_mapper/plugins/version.rb
  2. +6 −2 lib/mongo_mapper/plugins/versioned.rb
@@ -2,7 +2,7 @@
module MongoMapper
module Plugins
module Versioned
- Version = '0.1.7'
+ Version = '0.1.8'
end
end
end
@@ -10,8 +10,8 @@ def versioned(options={})
key :version_number, Integer, :default => 0, :index => true
many :versions, :class => MongoMapper::Plugins::Versioned::Version, :foreign_key => :versioned_id, :dependent => :destroy, :order => :version_number.asc
- after_create :create_version
- before_update :create_version, :if => Proc.new{ |doc| doc.should_create_version? }
+ after_create :create_version, :if => :should_create_initial_version?
+ before_update :create_version, :if => :should_create_version?
define_method "ignored_keys" do
configuration[:ignored_keys]
@@ -48,6 +48,10 @@ def current_version
def version_at(target_version_number)
versions.where(:version_number => target_version_number).first
end
+
+ def should_create_initial_version?
+ versions.empty?
+ end
# this method might be overwritten
# by something more sophisticated (esp. in case of EmbeddedDocuments)

0 comments on commit 691c510

Please sign in to comment.