Skip to content
Browse files

added associations to identity map

  • Loading branch information...
1 parent 20c07b3 commit ac22721f2aad679223d5492dfe82412197eb6a54 @pjdavis committed Mar 9, 2010
Showing with 31 additions and 0 deletions.
  1. +31 −0 lib/identity_map/active_record/associations.rb
View
31 lib/identity_map/active_record/associations.rb
@@ -0,0 +1,31 @@
+module IdentityMap
+
+ def self.included(base)
+ base.extend(ClassMethods)
+ class << base
+ alias_method_chain :association_instance_set, :identity_map
+ end
+ end
+
+ module ClassMethods
+
+ private
+
+ # Set the specified association instance.
+ def association_instance_set_with_identity_map(name, association)
+ identity_map = Thread.current['identity_map']
+ unless identity_map
+ association_instance_set_without_identity_map("@#{name}", association)
+ else
+ association_instance_set_without_identity_map("@#{name}", identity_map.put(association))
+ end
+ end
+
+
+ end
+
+end
+
+if Object.const_defined?("ActiveRecord")
+ ActiveRecord::Associations.send :include, IdentityMap
+end

0 comments on commit ac22721

Please sign in to comment.
Something went wrong with that request. Please try again.