Sha256: e08db8b9d58869bdf092d6cf4934f1261a85a4e4c5a644bfecb814f504b31cef

Contents?: true

Size: 877 Bytes

Versions: 18

Compression:

Stored size: 877 Bytes

Contents

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

MongoMapper.database = 'testing'

class User
  include MongoMapper::Document
  plugin MongoMapper::Plugins::IdentityMap

  key :name, String
end
User.delete_all

user = User.create(:name => 'John')

# User gets added to map on save
pp User.identity_map[user.id]

# Does not matter how you find user, it is always the same object until the identity map is cleared
puts "#{User.identity_map[user.id].object_id} == #{user.object_id}"
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
puts "Should be nil: " + User.identity_map[user.id].inspect


Version data entries

18 entries across 18 versions & 7 rubygems

Version Path
lookout-mongo_mapper-0.11.3 examples/identity_map.rb
mongo_mapper-0.11.2 examples/identity_map.rb
jamieorc-mongo_mapper-0.11.1.1 examples/identity_map.rb
mongo_mapper-0.11.1 examples/identity_map.rb
mongo_mapper-0.11.0 examples/identity_map.rb
mongo_mapper-0.10.1 examples/identity_map.rb
mongo_mapper-0.10.0 examples/identity_map.rb
mongo_mapper-0.9.2 examples/identity_map.rb
jonbell-mongo_mapper-0.8.6 examples/identity_map.rb
mongo_mapper-0.9.1 examples/identity_map.rb
mongo_mapper-0.9.0 examples/identity_map.rb
ign-mongo_mapper-0.8.6.2 examples/identity_map.rb
ign-mongo_mapper-0.8.6.1 examples/identity_map.rb
ssherman-mongo_mapper-0.8.6 examples/identity_map.rb
mongo_mapper-0.8.6 examples/identity_map.rb
mongo_mapper-0.8.5 examples/identity_map.rb
honkster-mongo_mapper-0.8.4 examples/identity_map.rb
mongo_mapper-0.8.4 examples/identity_map.rb