lib/mongoid/versioning.rb in mongoid-2.2.6 vs lib/mongoid/versioning.rb in mongoid-2.3.0
- old
+ new
@@ -13,10 +13,11 @@
embeds_many \
:versions,
:class_name => self.name,
:validate => false,
:cyclic => true,
+ :inverse_of => nil,
:versioned => true
set_callback :save, :before, :revise, :if => :revisable?
class_attribute :version_max
@@ -45,13 +46,13 @@
#
# @since 1.0.0
def revise
previous = previous_revision
if previous && versioned_attributes_changed?
- versions.build(previous.versioned_attributes)
+ versions.build(previous.versioned_attributes).attributes.delete("_id")
if version_max.present? && versions.length > version_max
- versions.delete(versions.first)
+ versions.shift
end
self.version = (version || 1 ) + 1
end
end
@@ -62,13 +63,11 @@
# person.revise!
#
# @since 2.2.1
def revise!
new_version = versions.build((previous_revision || self).versioned_attributes)
- if version_max.present? && versions.length > version_max
- versions.delete(versions.first)
- end
+ versions.shift if version_max.present? && versions.length > version_max
self.version = (version || 1 ) + 1
save
end
# Filters the results of +changes+ by removing any fields that should
@@ -169,10 +168,10 @@
# @return [ Hash ] The hash without non-versioned columns.
#
# @since 2.1.0
def only_versioned_attributes(hash)
{}.tap do |versioned|
- hash.except("versions", "_id").each_pair do |name, value|
+ hash.except("versions").each_pair do |name, value|
field = fields[name]
versioned[name] = value if !field || field.versioned?
end
end
end