Module: MongoMapper::Plugins::IdentityMap::ClassMethods::IdentityMapQueryMethods

Defined in:
lib/mongo_mapper/plugins/identity_map.rb

Instance Method Summary collapse

Instance Method Details

#all(opts = {}) ⇒ Object



34
35
36
37
38
39
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 34

def all(opts={})
  query = clone.update(opts)
  super.tap do |docs|
    model.remove_documents_from_map(docs) if query.fields?
  end
end

#find_one(opts = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mongo_mapper/plugins/identity_map.rb', line 41

def find_one(opts={})
  query = clone.update(opts)

  if query.simple? && model.identity_map[query[:_id]]
    model.identity_map[query[:_id]]
  else
    super.tap do |doc|
      model.remove_documents_from_map(doc) if query.fields?
    end
  end
end