Skip to content

Commit

Permalink
MONGOID-5208 update function to return nil
Browse files Browse the repository at this point in the history
  • Loading branch information
Neilshweky committed Dec 30, 2021
1 parent 7ad4168 commit 6cb017d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/mongoid/reloadable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def reload
end

reloaded = _reload
if Mongoid.raise_not_found_error && reloaded.empty?
if Mongoid.raise_not_found_error && (reloaded.nil? || reloaded.empty?)
raise Errors::DocumentNotFound.new(self.class, _id, _id)
end
@attributes = reloaded
Expand Down Expand Up @@ -78,11 +78,12 @@ def reload_embedded_document
#
# @param [ Hash ] attributes The document in the db.
#
# @return [ Hash ] The document's extracted attributes.
# @return [ Hash | nil ] The document's extracted attributes or nil if the
# document doesn't exist.
def extract_embedded_attributes(attributes)
atomic_position.split(".").inject(attributes) do |attrs, part|
attrs = attrs[part =~ /\d/ ? part.to_i : part]
attrs || {}
attrs
end
end
end
Expand Down

0 comments on commit 6cb017d

Please sign in to comment.