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



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

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

#find_one(opts = {}) ⇒ Object



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

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

  if model.identity_map_on? && 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