aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/builder/belongs_to.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/associations/builder/belongs_to.rb')
-rw-r--r--activerecord/lib/active_record/associations/builder/belongs_to.rb23
1 files changed, 13 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/associations/builder/belongs_to.rb b/activerecord/lib/active_record/associations/builder/belongs_to.rb
index 81293e464d..4e88b50ec5 100644
--- a/activerecord/lib/active_record/associations/builder/belongs_to.rb
+++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb
@@ -12,17 +12,21 @@ 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(model, reflection)
+ super
+ add_counter_cache_callbacks(model, reflection) if options[:counter_cache]
+ add_touch_callbacks(model, reflection) if options[:touch]
+ end
+
+ def define_accessors(mixin)
+ super
+ add_counter_cache_methods mixin
+ end
+
private
def add_counter_cache_methods(mixin)
@@ -70,9 +74,8 @@ module ActiveRecord::Associations::Builder
end
end
- def add_counter_cache_callbacks(reflection)
+ def add_counter_cache_callbacks(model, reflection)
cache_column = reflection.counter_cache_column
- add_counter_cache_methods mixin
association = self
model.after_create lambda { |record|
@@ -117,7 +120,7 @@ module ActiveRecord::Associations::Builder
end
end
- def add_touch_callbacks(reflection)
+ def add_touch_callbacks(model, reflection)
foreign_key = reflection.foreign_key
n = name
touch = options[:touch]