lib/mongoid/relations/targets/enumerable.rb in mongoid-3.0.23 vs lib/mongoid/relations/targets/enumerable.rb in mongoid-3.1.0
- old
+ new
@@ -161,11 +161,11 @@
if _loaded?
_loaded.each_pair do |id, doc|
yield(doc)
end
else
- _unloaded.each do |doc|
+ unloaded_documents.each do |doc|
document = _added.delete(doc.id) || _loaded.delete(doc.id) || doc
_loaded[document.id] = document
yield(document)
end
end
@@ -445,9 +445,13 @@
def matching_document(location)
_loaded.try(:values).try(location) ||
_added[(ul = _unloaded.try(location)).try(:id)] ||
ul ||
_added.values.try(location)
+ end
+
+ def unloaded_documents
+ _unloaded.selector.values.any?(&:blank_criteria?) ? [] : _unloaded
end
end
end
end
end