Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #447 from darragh/fix_identity_map_with_fields_and…

…_each

partial records incorrectly added to IdentityMap when using Plucky::Query#each
  • Loading branch information...
commit 37231503ddc1d98fe36e4eb50486ee7fb46e2ee4 2 parents 2fed18d + 1bead1a
@jnunemaker jnunemaker authored
View
8 lib/mongo_mapper/plugins/identity_map.rb
@@ -76,6 +76,14 @@ def find_one(opts={})
end
end
end
+
+ def find_each(opts={}, &block)
+ query = clone.amend(opts)
+ super(opts) do |doc|
+ model.remove_documents_from_map(doc) if query.fields?
+ block.call(doc) unless block.nil?
+ end
+ end
end
def query(opts={})
View
7 test/functional/test_identity_map.rb
@@ -372,6 +372,13 @@ def clear_identity_map
assert_not_in_map(@person)
end
+ should "not add to map using where and each" do
+ @person_class.where(:id => @person.id).each{|_|}
+ assert_in_map(@person)
+ @person_class.where(:id => @person.id).only(:id).each{|_|}
+ assert_not_in_map(@person)
+ end
+
should "return nil if not found" do
@person_class.fields(:name).find(BSON::ObjectId.new).should be_nil
end
Please sign in to comment.
Something went wrong with that request. Please try again.