- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
Active Record Identity Map
Ensures that each object gets loaded only once by keeping every loaded object in a map. Looks up objects using the map when referring to them.
More information on Identity Map pattern:
http://www.martinfowler.com/eaaCatalog/identityMap.html
Configuration
In order to enable IdentityMap, set config.active_record.identity_map = true in your config/application.rb file.
IdentityMap is disabled by default and still in development (i.e. use it with care).
Associations
Active Record Identity Map does not track associations yet. For example:
comment = @post.comments.first comment.post = nil @post.comments.include?(comment) #=> true
Ideally, the example above would return false, removing the comment object from the post association when the association is nullified. This may cause side effects, as in the situation below, if Identity Map is enabled:
Post.has_many :comments, :dependent => :destroy comment = @post.comments.first comment.post = nil comment.save Post.destroy(@post.id)
Without using Identity Map, the code above will destroy the @post object leaving the comment object intact. However, once we enable Identity Map, the post loaded by Post.destroy is exactly the same object as the object @post. As the object @post still has the comment object in @post.comments, once Identity Map is enabled, the comment object will be accidently removed.
This inconsistency is meant to be fixed in future Rails releases.