aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2004-12-22 13:54:44 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2004-12-22 13:54:44 +0000
commit4b229d1034b796e316c8e18ada4b8524d0ab3976 (patch)
tree29491de6ea951d0560228e244c3d8a9349be4bc2 /activerecord
parent951c9426ad37b89bbab5de1389ceea337da623cf (diff)
downloadrails-4b229d1034b796e316c8e18ada4b8524d0ab3976.tar.gz
rails-4b229d1034b796e316c8e18ada4b8524d0ab3976.tar.bz2
rails-4b229d1034b796e316c8e18ada4b8524d0ab3976.zip
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
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/associations.rb7
2 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index e2a98e9fcd..de7ccd163d 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Added Base#clear_association_cache to empty all the cached associations #347 [Tobias Luetke]
+
* Added more informative exceptions in establish_connection #356 [bitsweat]
* Fixed that options[:counter_sql] was overwritten with interpolated sql rather than original sql #355 [bitsweat]
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 68a646f5c6..0336b5d1d3 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -34,6 +34,13 @@ module ActiveRecord
base.extend(ClassMethods)
end
+ # Clears out the association cache
+ def clear_association_cache #:nodoc:
+ self.class.reflect_on_all_associations.to_a.each do |assoc|
+ instance_variable_set "@#{assoc.name}", nil
+ end
+ end
+
# Associations are a set of macro-like class methods for tying objects together through foreign keys. They express relationships like
# "Project has one Project Manager" or "Project belongs to a Portfolio". Each macro adds a number of methods to the class which are
# specialized according to the collection or association symbol and the options hash. It works much the same was as Ruby's own attr*