Skip to content

Commit

Permalink
Added Base#clear_association_cache to empty all the cached associations
Browse files Browse the repository at this point in the history
#347 [Tobias Luetke]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@252 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Dec 22, 2004
1 parent 951c942 commit 4b229d1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions 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]
Expand Down
7 changes: 7 additions & 0 deletions activerecord/lib/active_record/associations.rb
Expand Up @@ -34,6 +34,13 @@ def self.append_features(base)
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*
Expand Down

0 comments on commit 4b229d1

Please sign in to comment.