Permalink
Browse files

DRY up association collection reader method generation.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4214 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 37758cd commit 7cc446acf49ffdec6d832bc90fe48e1f2f8683cf Marcel Molina committed Apr 15, 2006
Showing with 7 additions and 6 deletions.
  1. +4 −0 activerecord/CHANGELOG
  2. +3 −6 activerecord/lib/active_record/associations.rb
@@ -1,5 +1,9 @@
*SVN*
+* DRY up association collection reader method generation. [Marcel Molina Jr.]
+
+* DRY up and tweak style of the validation error object. [Marcel Molina Jr.]
+
* Add :case_sensitive option to validates_uniqueness_of (closes #3090) [Rick]
class Account < ActiveRecord::Base
@@ -895,11 +895,8 @@ def collection_accessor_methods(reflection, association_proxy_class)
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 @@ def column_aliases(join_dependency)
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

0 comments on commit 7cc446a

Please sign in to comment.