Skip to content
This repository
Browse code

Added Base#clear_association_cache to empty all the cached associations

#347 [Tobias Luetke]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@252 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 4b229d1034b796e316c8e18ada4b8524d0ab3976 1 parent 951c942
David Heinemeier Hansson authored December 22, 2004
2  activerecord/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *SVN*
2 2
 
  3
+* Added Base#clear_association_cache to empty all the cached associations #347 [Tobias Luetke]
  4
+
3 5
 * Added more informative exceptions in establish_connection #356 [bitsweat]
4 6
 
5 7
 * Fixed that options[:counter_sql] was overwritten with interpolated sql rather than original sql #355 [bitsweat]
7  activerecord/lib/active_record/associations.rb
@@ -34,6 +34,13 @@ def self.append_features(base)
34 34
       base.extend(ClassMethods)
35 35
     end
36 36
 
  37
+    # Clears out the association cache 
  38
+    def clear_association_cache #:nodoc:
  39
+      self.class.reflect_on_all_associations.to_a.each do |assoc|
  40
+        instance_variable_set "@#{assoc.name}", nil
  41
+      end
  42
+    end
  43
+
37 44
     # Associations are a set of macro-like class methods for tying objects together through foreign keys. They express relationships like 
38 45
     # "Project has one Project Manager" or "Project belongs to a Portfolio". Each macro adds a number of methods to the class which are 
39 46
     # specialized according to the collection or association symbol and the options hash. It works much the same was as Ruby's own attr* 

0 notes on commit 4b229d1

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