Skip to content

Instantly share code, notes, and snippets.

@cgriego
Created May 4, 2010 22:06
Show Gist options
  • Save cgriego/390091 to your computer and use it in GitHub Desktop.
Save cgriego/390091 to your computer and use it in GitHub Desktop.
From 14c3cd15dd0f50dc02fcfa1a01ad93c723bba36d Mon Sep 17 00:00:00 2001
From: Chris Griego <[email protected]>
Date: Tue, 4 May 2010 17:05:42 -0500
Subject: [PATCH] Fix halting callbacks
---
lib/mongoid/persistence.rb | 3 ++-
lib/mongoid/persistence/insert.rb | 3 +--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/mongoid/persistence.rb b/lib/mongoid/persistence.rb
index d61f970..7c03d24 100644
--- a/lib/mongoid/persistence.rb
+++ b/lib/mongoid/persistence.rb
@@ -120,7 +120,8 @@ module Mongoid #:nodoc:
def upsert(validate = true)
validate = parse_validate(validate)
if new_record?
- insert(validate).errors.any? ? false : true
+ document = insert(validate)
+ !document.errors.any? || document.persisted?
else
update(validate)
end
diff --git a/lib/mongoid/persistence/insert.rb b/lib/mongoid/persistence/insert.rb
index 007bb6b..909ffaf 100644
--- a/lib/mongoid/persistence/insert.rb
+++ b/lib/mongoid/persistence/insert.rb
@@ -29,9 +29,8 @@ module Mongoid #:nodoc:
@document.new_record = false
@document.move_changes
end
- @document
end
- end
+ end; @document
end
protected
--
1.6.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment