Sha256: d495cb4bb150450ada65af8f3cb8d4423bf6452321174baa258bac97421951bb

Contents?: true

Size: 723 Bytes

Versions: 15

Compression:

Stored size: 723 Bytes

Contents

$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
require 'mongo_mapper'
require 'pp'

MongoMapper.database = 'testing'

MongoMapper::Plugins::IdentityMap.enabled = true

class User
  include MongoMapper::Document

  key :name, String
end
User.delete_all

# User gets added to map on save
user = User.create(:name => 'John')

# Does not matter how you find user, it is always the same object until the identity map is cleared
puts "#{User.find(user.id).object_id} == #{user.object_id}"
puts "#{User.all[0].object_id} == #{user.object_id}"

MongoMapper::Plugins::IdentityMap.clear
puts "#{User.find(user.id).object_id} != #{user.object_id}"

# User gets removed from map on destroy
user = User.create
user.destroy

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
mongo_mapper-0.16.0 examples/identity_map.rb
mongo_mapper-0.15.6 examples/identity_map.rb
mongo_mapper-0.15.5 examples/identity_map.rb
mongo_mapper-0.15.4 examples/identity_map.rb
mongo_mapper-0.15.3 examples/identity_map.rb
mongo_mapper-0.15.2 examples/identity_map.rb
mongo_mapper-0.15.1 examples/identity_map.rb
mongo_mapper-0.15.0 examples/identity_map.rb
mongo_mapper-0.14.0 examples/identity_map.rb
mongo_mapper-0.14.0.rc1 examples/identity_map.rb
mongo_mapper-0.13.1 examples/identity_map.rb
mongo_mapper-0.13.0 examples/identity_map.rb
mongo_mapper-0.13.0.beta2 examples/identity_map.rb
mongo_mapper-0.13.0.beta1 examples/identity_map.rb
mongo_mapper-0.12.0 examples/identity_map.rb