From b86a4965b8532286430b7cd9b359a2574d745b92 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 2 Oct 2013 15:27:18 -0700 Subject: [PATCH] we can define callbacks without a builder instance --- .../lib/active_record/associations/builder/association.rb | 6 +++--- .../lib/active_record/associations/builder/belongs_to.rb | 6 +++--- .../associations/builder/collection_association.rb | 4 ++-- .../associations/builder/has_and_belongs_to_many.rb | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb index dd2a6415b4..6cf5523ad6 100644 --- a/activerecord/lib/active_record/associations/builder/association.rb +++ b/activerecord/lib/active_record/associations/builder/association.rb @@ -32,7 +32,7 @@ module ActiveRecord::Associations::Builder builder = new(name, scope, options, &block) reflection = builder.build(model) builder.define_accessors model, reflection - builder.define_callbacks model, reflection + define_callbacks model, reflection builder.define_extensions model reflection end @@ -68,8 +68,8 @@ module ActiveRecord::Associations::Builder def define_extensions(model) end - def define_callbacks(model, reflection) - self.class.add_before_destroy_callbacks(model, reflection) if reflection.options[:dependent] + def self.define_callbacks(model, reflection) + add_before_destroy_callbacks(model, reflection) if reflection.options[:dependent] Association.extensions.each do |extension| extension.build model, reflection end diff --git a/activerecord/lib/active_record/associations/builder/belongs_to.rb b/activerecord/lib/active_record/associations/builder/belongs_to.rb index 6d590c8220..9d55ec850e 100644 --- a/activerecord/lib/active_record/associations/builder/belongs_to.rb +++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb @@ -12,10 +12,10 @@ module ActiveRecord::Associations::Builder [:destroy, :delete] end - def define_callbacks(model, reflection) + def self.define_callbacks(model, reflection) super - self.class.add_counter_cache_callbacks(model, reflection) if reflection.options[:counter_cache] - self.class.add_touch_callbacks(model, reflection) if reflection.options[:touch] + add_counter_cache_callbacks(model, reflection) if reflection.options[:counter_cache] + add_touch_callbacks(model, reflection) if reflection.options[:touch] end def define_accessors(mixin, reflection) diff --git a/activerecord/lib/active_record/associations/builder/collection_association.rb b/activerecord/lib/active_record/associations/builder/collection_association.rb index 68f60a76b0..15f9f9a65f 100644 --- a/activerecord/lib/active_record/associations/builder/collection_association.rb +++ b/activerecord/lib/active_record/associations/builder/collection_association.rb @@ -23,12 +23,12 @@ module ActiveRecord::Associations::Builder end end - def define_callbacks(model, reflection) + def self.define_callbacks(model, reflection) super name = reflection.name options = reflection.options CALLBACKS.each { |callback_name| - self.class.define_callback(model, callback_name, name, options) + define_callback(model, callback_name, name, options) } end diff --git a/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb b/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb index abe6357185..50c9dbe73f 100644 --- a/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb +++ b/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb @@ -8,7 +8,7 @@ module ActiveRecord::Associations::Builder super + [:join_table, :association_foreign_key] end - def define_callbacks(model, reflection) + def self.define_callbacks(model, reflection) super name = reflection.name model.send(:include, Module.new {