Skip to content

Commit

Permalink
Don't persist in a create block when reading for validation. Fixes #1…
Browse files Browse the repository at this point in the history
…372.
  • Loading branch information
durran committed Oct 23, 2011
1 parent cc9d285 commit 184376b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -14,6 +14,8 @@ For instructions on upgrading to newer versions, visit

* \#1373 Warn if a scope overrides another scope.

* \#1372 Never persist when binding inside of a read attribute for validation.

* \#1364 Fixed reloading of documents with non bson object id ids.

* \#1360 Fixed performance of Mongoid's observer instantiation by hooking into
Expand Down
2 changes: 1 addition & 1 deletion lib/mongoid/relations/referenced/many.rb
Expand Up @@ -33,7 +33,7 @@ def <<(*args)
args.flatten.each do |doc|
next unless doc
append(doc)
doc.save if persistable?
doc.save if persistable? && !doc.validated?
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/mongoid/validations.rb
Expand Up @@ -44,7 +44,9 @@ def exit_validate
# @since 2.0.0.rc.1
def read_attribute_for_validation(attr)
if relations[attr.to_s]
begin_validate
relation = send(attr)
exit_validate
relation.do_or_do_not(:in_memory) || relation
else
send(attr)
Expand Down

0 comments on commit 184376b

Please sign in to comment.