aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-08-01 10:01:14 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-08-01 11:02:15 -0700
commit49d50b9d80957e53a72ba8ffa1dd51f1247610b5 (patch)
tree69be1991364dede566b0f98af2698bf8215319df /activerecord
parent35f94acf55f0d4dbcba747601434736685e9924f (diff)
downloadrails-49d50b9d80957e53a72ba8ffa1dd51f1247610b5.tar.gz
rails-49d50b9d80957e53a72ba8ffa1dd51f1247610b5.tar.bz2
rails-49d50b9d80957e53a72ba8ffa1dd51f1247610b5.zip
extract more mutations to the caller
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/builder/association.rb16
-rw-r--r--activerecord/lib/active_record/associations/builder/belongs_to.rb13
2 files changed, 16 insertions, 13 deletions
diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb
index 9800013ee5..9b304cb5e6 100644
--- a/activerecord/lib/active_record/associations/builder/association.rb
+++ b/activerecord/lib/active_record/associations/builder/association.rb
@@ -26,8 +26,10 @@ module ActiveRecord::Associations::Builder
raise ArgumentError, "association names must be a Symbol" unless name.kind_of?(Symbol)
builder = new(model, name, scope, options, &block)
+ reflection = builder.build
builder.define_accessors model.generated_feature_methods
- builder.build
+ builder.define_callbacks reflection
+ reflection
end
def initialize(model, name, scope, options)
@@ -52,11 +54,7 @@ module ActiveRecord::Associations::Builder
def build
configure_dependency if options[:dependent]
- reflection = ActiveRecord::Reflection.create(macro, name, scope, options, model)
- Association.extensions.each do |extension|
- extension.build @model, reflection
- end
- reflection
+ ActiveRecord::Reflection.create(macro, name, scope, options, model)
end
def macro
@@ -71,6 +69,12 @@ module ActiveRecord::Associations::Builder
options.assert_valid_keys(valid_options)
end
+ def define_callbacks(reflection)
+ Association.extensions.each do |extension|
+ extension.build @model, reflection
+ end
+ end
+
# Defines the setter and getter methods for the association
# class Post < ActiveRecord::Base
# has_many :comments
diff --git a/activerecord/lib/active_record/associations/builder/belongs_to.rb b/activerecord/lib/active_record/associations/builder/belongs_to.rb
index 0c3b3847cc..a4e314b7fb 100644
--- a/activerecord/lib/active_record/associations/builder/belongs_to.rb
+++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb
@@ -12,17 +12,16 @@ module ActiveRecord::Associations::Builder
!options[:polymorphic]
end
- def build
- reflection = super
- add_counter_cache_callbacks(reflection) if options[:counter_cache]
- add_touch_callbacks(reflection) if options[:touch]
- reflection
- end
-
def valid_dependent_options
[:destroy, :delete]
end
+ def define_callbacks(reflection)
+ super
+ add_counter_cache_callbacks(reflection) if options[:counter_cache]
+ add_touch_callbacks(reflection) if options[:touch]
+ end
+
def define_accessors(mixin)
super
add_counter_cache_methods mixin