aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations.rb
diff options
context:
space:
mode:
authorMarcel Molina <marcel@vernix.org>2006-04-15 23:24:59 +0000
committerMarcel Molina <marcel@vernix.org>2006-04-15 23:24:59 +0000
commit7cc446acf49ffdec6d832bc90fe48e1f2f8683cf (patch)
tree3ec60a0b93aaeca202adcc40e9e66cb71fa7b006 /activerecord/lib/active_record/associations.rb
parent37758cde13b2d15d11b2a9e407d9c269cd24715f (diff)
downloadrails-7cc446acf49ffdec6d832bc90fe48e1f2f8683cf.tar.gz
rails-7cc446acf49ffdec6d832bc90fe48e1f2f8683cf.tar.bz2
rails-7cc446acf49ffdec6d832bc90fe48e1f2f8683cf.zip
DRY up association collection reader method generation.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4214 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb9
1 files changed, 3 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index f862d9e777..0099a461e1 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -895,11 +895,8 @@ module ActiveRecord
collection_reader_method(reflection, association_proxy_class)
define_method("#{reflection.name}=") do |new_value|
- association = instance_variable_get("@#{reflection.name}")
- unless association.respond_to?(:loaded?)
- association = association_proxy_class.new(self, reflection)
- instance_variable_set("@#{reflection.name}", association)
- end
+ # Loads proxy class instance (defined in collection_reader_method) if not already loaded
+ association = send(reflection.name)
association.replace(new_value)
association
end
@@ -1224,7 +1221,7 @@ module ActiveRecord
def add_association_callbacks(association_name, options)
callbacks = %w(before_add after_add before_remove after_remove)
callbacks.each do |callback_name|
- full_callback_name = "#{callback_name.to_s}_for_#{association_name.to_s}"
+ full_callback_name = "#{callback_name}_for_#{association_name}"
defined_callbacks = options[callback_name.to_sym]
if options.has_key?(callback_name.to_sym)
class_inheritable_reader full_callback_name.to_sym