Skip to content

Commit

Permalink
Merge pull request #40 from simi/use-custom-update
Browse files Browse the repository at this point in the history
Don't override mongoid original update.
  • Loading branch information
simi committed Sep 28, 2015
2 parents b7631ce + cd5f864 commit f793ee2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/mongoid/paranoia.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def persisted?
def remove_with_paranoia(options = {})
cascade!
time = self.deleted_at = Time.now
update("$set" => { paranoid_field => time })
_paranoia_update("$set" => { paranoid_field => time })
@destroyed = true
true
end
Expand Down Expand Up @@ -145,7 +145,7 @@ def destroyed?
# @since 1.0.0
def restore(opts = {})
run_callbacks(:restore) do
update("$unset" => { paranoid_field => true })
_paranoia_update("$unset" => { paranoid_field => true })
attributes.delete("deleted_at")
@destroyed = false
restore_relations if opts[:recursive]
Expand Down Expand Up @@ -193,10 +193,10 @@ def paranoid_field
embedded? ? "#{atomic_position}.#{field}" : field
end

# Update value in the collection.
# Update value in the collection (compatibility layer for Mongoid 4/5).
#
# @return [ Object ] Update result.
def update(value)
def _paranoia_update(value)
query = paranoid_collection.find(atomic_selector)
if Mongoid::Compatibility::Version.mongoid5?
query.update_one(value)
Expand Down

0 comments on commit f793ee2

Please sign in to comment.