Skip to content

Commit

Permalink
Merge pull request mongomapper#447 from darragh/fix_identity_map_with…
Browse files Browse the repository at this point in the history
…_fields_and_each

partial records incorrectly added to IdentityMap when using Plucky::Query#each
  • Loading branch information
greatuserongithub committed Sep 7, 2012
2 parents 2fed18d + 1bead1a commit 3723150
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/mongo_mapper/plugins/identity_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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={})
Expand Down
7 changes: 7 additions & 0 deletions test/functional/test_identity_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3723150

Please sign in to comment.