From c2b337183814cbd028407830509ce1da52e0e031 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 2 Oct 2013 14:34:51 -0700 Subject: decouple define_callback from the instance --- .../active_record/associations/builder/collection_association.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/associations/builder') diff --git a/activerecord/lib/active_record/associations/builder/collection_association.rb b/activerecord/lib/active_record/associations/builder/collection_association.rb index 7bd0687c0b..38a70f3efd 100644 --- a/activerecord/lib/active_record/associations/builder/collection_association.rb +++ b/activerecord/lib/active_record/associations/builder/collection_association.rb @@ -25,7 +25,9 @@ module ActiveRecord::Associations::Builder def define_callbacks(model, reflection) super - CALLBACKS.each { |callback_name| define_callback(model, callback_name) } + CALLBACKS.each { |callback_name| + define_callback(model, callback_name, reflection.name, reflection.options) + } end def define_extensions(model) @@ -35,7 +37,7 @@ module ActiveRecord::Associations::Builder end end - def define_callback(model, callback_name) + def define_callback(model, callback_name, name, options) full_callback_name = "#{callback_name}_for_#{name}" # TODO : why do i need method_defined? I think its because of the inheritance chain -- cgit v1.2.3 From 5d8b7760ee3700c6d897e51e01dd2055da80506b Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 2 Oct 2013 14:38:05 -0700 Subject: name is on the reflection, so just use the reflection --- activerecord/lib/active_record/associations/builder/belongs_to.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activerecord/lib/active_record/associations/builder') diff --git a/activerecord/lib/active_record/associations/builder/belongs_to.rb b/activerecord/lib/active_record/associations/builder/belongs_to.rb index 4e88b50ec5..51d963e18d 100644 --- a/activerecord/lib/active_record/associations/builder/belongs_to.rb +++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb @@ -34,7 +34,7 @@ module ActiveRecord::Associations::Builder mixin.class_eval do def belongs_to_counter_cache_after_create(association, reflection) - if record = send(association.name) + if record = send(reflection.name) cache_column = reflection.counter_cache_column record.class.increment_counter(cache_column, record.id) @_after_create_counter_called = true @@ -44,7 +44,7 @@ module ActiveRecord::Associations::Builder def belongs_to_counter_cache_before_destroy(association, reflection) foreign_key = reflection.foreign_key.to_sym unless destroyed_by_association && destroyed_by_association.foreign_key.to_sym == foreign_key - record = send association.name + record = send reflection.name if record && !self.destroyed? cache_column = reflection.counter_cache_column record.class.decrement_counter(cache_column, record.id) -- cgit v1.2.3 From 75beb6c7c3173ba78f212cfeccaa172beccf4e92 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 2 Oct 2013 14:52:59 -0700 Subject: push constructable? on to the reflection --- .../lib/active_record/associations/builder/association.rb | 4 ++-- activerecord/lib/active_record/associations/builder/belongs_to.rb | 8 ++------ activerecord/lib/active_record/associations/builder/has_one.rb | 4 ---- .../active_record/associations/builder/singular_association.rb | 8 ++------ 4 files changed, 6 insertions(+), 18 deletions(-) (limited to 'activerecord/lib/active_record/associations/builder') diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb index 1059fc032d..b8a856f001 100644 --- a/activerecord/lib/active_record/associations/builder/association.rb +++ b/activerecord/lib/active_record/associations/builder/association.rb @@ -31,7 +31,7 @@ module ActiveRecord::Associations::Builder builder = new(name, scope, options, &block) reflection = builder.build(model) - builder.define_accessors model + builder.define_accessors model, reflection builder.define_callbacks model, reflection builder.define_extensions model reflection @@ -82,7 +82,7 @@ module ActiveRecord::Associations::Builder # # Post.first.comments and Post.first.comments= methods are defined by this method... - def define_accessors(model) + def define_accessors(model, reflection) mixin = model.generated_feature_methods define_readers(mixin) define_writers(mixin) diff --git a/activerecord/lib/active_record/associations/builder/belongs_to.rb b/activerecord/lib/active_record/associations/builder/belongs_to.rb index 51d963e18d..a2f4758b57 100644 --- a/activerecord/lib/active_record/associations/builder/belongs_to.rb +++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb @@ -8,10 +8,6 @@ module ActiveRecord::Associations::Builder super + [:foreign_type, :polymorphic, :touch] end - def constructable? - !options[:polymorphic] - end - def valid_dependent_options [:destroy, :delete] end @@ -22,7 +18,7 @@ module ActiveRecord::Associations::Builder add_touch_callbacks(model, reflection) if options[:touch] end - def define_accessors(mixin) + def define_accessors(mixin, reflection) super add_counter_cache_methods mixin end @@ -58,7 +54,7 @@ module ActiveRecord::Associations::Builder if (@_after_create_counter_called ||= false) @_after_create_counter_called = false - elsif attribute_changed?(foreign_key) && !new_record? && association.constructable? + elsif attribute_changed?(foreign_key) && !new_record? && reflection.constructable? model = reflection.klass foreign_key_was = attribute_was foreign_key foreign_key = attribute foreign_key diff --git a/activerecord/lib/active_record/associations/builder/has_one.rb b/activerecord/lib/active_record/associations/builder/has_one.rb index 62d454ce55..accd29e5ef 100644 --- a/activerecord/lib/active_record/associations/builder/has_one.rb +++ b/activerecord/lib/active_record/associations/builder/has_one.rb @@ -10,10 +10,6 @@ module ActiveRecord::Associations::Builder valid end - def constructable? - !options[:through] - end - def valid_dependent_options [:destroy, :delete, :nullify, :restrict_with_error, :restrict_with_exception] end diff --git a/activerecord/lib/active_record/associations/builder/singular_association.rb b/activerecord/lib/active_record/associations/builder/singular_association.rb index d97c0e9afd..10d568ebc0 100644 --- a/activerecord/lib/active_record/associations/builder/singular_association.rb +++ b/activerecord/lib/active_record/associations/builder/singular_association.rb @@ -6,13 +6,9 @@ module ActiveRecord::Associations::Builder super + [:remote, :dependent, :counter_cache, :primary_key, :inverse_of] end - def constructable? - true - end - - def define_accessors(model) + def define_accessors(model, reflection) super - define_constructors(model.generated_feature_methods) if constructable? + define_constructors(model.generated_feature_methods) if reflection.constructable? end # Defines the (build|create)_association methods for belongs_to or has_one association -- cgit v1.2.3 From 438e172a4598736e3ed1b3d6eddbe2396651a0ef Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 2 Oct 2013 14:55:29 -0700 Subject: association builder is no longer needed for counter cache, so remove it --- .../lib/active_record/associations/builder/belongs_to.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'activerecord/lib/active_record/associations/builder') diff --git a/activerecord/lib/active_record/associations/builder/belongs_to.rb b/activerecord/lib/active_record/associations/builder/belongs_to.rb index a2f4758b57..2755eb7c6d 100644 --- a/activerecord/lib/active_record/associations/builder/belongs_to.rb +++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb @@ -29,7 +29,7 @@ module ActiveRecord::Associations::Builder return if mixin.method_defined? :belongs_to_counter_cache_after_create mixin.class_eval do - def belongs_to_counter_cache_after_create(association, reflection) + def belongs_to_counter_cache_after_create(reflection) if record = send(reflection.name) cache_column = reflection.counter_cache_column record.class.increment_counter(cache_column, record.id) @@ -37,7 +37,7 @@ module ActiveRecord::Associations::Builder end end - def belongs_to_counter_cache_before_destroy(association, reflection) + def belongs_to_counter_cache_before_destroy(reflection) foreign_key = reflection.foreign_key.to_sym unless destroyed_by_association && destroyed_by_association.foreign_key.to_sym == foreign_key record = send reflection.name @@ -48,7 +48,7 @@ module ActiveRecord::Associations::Builder end end - def belongs_to_counter_cache_after_update(association, reflection) + def belongs_to_counter_cache_after_update(reflection) foreign_key = reflection.foreign_key cache_column = reflection.counter_cache_column @@ -72,18 +72,17 @@ module ActiveRecord::Associations::Builder def add_counter_cache_callbacks(model, reflection) cache_column = reflection.counter_cache_column - association = self model.after_create lambda { |record| - record.belongs_to_counter_cache_after_create(association, reflection) + record.belongs_to_counter_cache_after_create(reflection) } model.before_destroy lambda { |record| - record.belongs_to_counter_cache_before_destroy(association, reflection) + record.belongs_to_counter_cache_before_destroy(reflection) } model.after_update lambda { |record| - record.belongs_to_counter_cache_after_update(association, reflection) + record.belongs_to_counter_cache_after_update(reflection) } klass = reflection.class_name.safe_constantize -- cgit v1.2.3 From a88a5d73704307f9fcd1187ddeba0bbfd7b5968c Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 2 Oct 2013 15:02:48 -0700 Subject: use the information on the reflection to determine whether callbacks should be added --- .../lib/active_record/associations/builder/association.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'activerecord/lib/active_record/associations/builder') diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb index b8a856f001..2edea96170 100644 --- a/activerecord/lib/active_record/associations/builder/association.rb +++ b/activerecord/lib/active_record/associations/builder/association.rb @@ -69,7 +69,7 @@ module ActiveRecord::Associations::Builder end def define_callbacks(model, reflection) - add_before_destroy_callbacks(model, name) if options[:dependent] + add_before_destroy_callbacks(model, reflection) if reflection.options[:dependent] Association.extensions.each do |extension| extension.build model, reflection end @@ -110,11 +110,12 @@ module ActiveRecord::Associations::Builder private - def add_before_destroy_callbacks(model, name) - unless valid_dependent_options.include? options[:dependent] - raise ArgumentError, "The :dependent option must be one of #{valid_dependent_options}, but is :#{options[:dependent]}" + def add_before_destroy_callbacks(model, reflection) + unless valid_dependent_options.include? reflection.options[:dependent] + raise ArgumentError, "The :dependent option must be one of #{valid_dependent_options}, but is :#{reflection.options[:dependent]}" end + name = reflection.name model.before_destroy lambda { |o| o.association(name).handle_dependency } end end -- cgit v1.2.3 From 22f05afb2d79f8088e49710d4e9e3ba1883bf11e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 2 Oct 2013 15:05:06 -0700 Subject: valid_options doesn't depend on the instance, so push it to the class --- activerecord/lib/active_record/associations/builder/association.rb | 6 +++--- activerecord/lib/active_record/associations/builder/belongs_to.rb | 2 +- activerecord/lib/active_record/associations/builder/has_many.rb | 2 +- activerecord/lib/active_record/associations/builder/has_one.rb | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'activerecord/lib/active_record/associations/builder') diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb index 2edea96170..e6da251550 100644 --- a/activerecord/lib/active_record/associations/builder/association.rb +++ b/activerecord/lib/active_record/associations/builder/association.rb @@ -104,15 +104,15 @@ module ActiveRecord::Associations::Builder CODE end - def valid_dependent_options + def self.valid_dependent_options raise NotImplementedError end private def add_before_destroy_callbacks(model, reflection) - unless valid_dependent_options.include? reflection.options[:dependent] - raise ArgumentError, "The :dependent option must be one of #{valid_dependent_options}, but is :#{reflection.options[:dependent]}" + unless self.class.valid_dependent_options.include? reflection.options[:dependent] + raise ArgumentError, "The :dependent option must be one of #{self.class.valid_dependent_options}, but is :#{reflection.options[:dependent]}" end name = reflection.name diff --git a/activerecord/lib/active_record/associations/builder/belongs_to.rb b/activerecord/lib/active_record/associations/builder/belongs_to.rb index 2755eb7c6d..1d9492a3bd 100644 --- a/activerecord/lib/active_record/associations/builder/belongs_to.rb +++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb @@ -8,7 +8,7 @@ module ActiveRecord::Associations::Builder super + [:foreign_type, :polymorphic, :touch] end - def valid_dependent_options + def self.valid_dependent_options [:destroy, :delete] end diff --git a/activerecord/lib/active_record/associations/builder/has_many.rb b/activerecord/lib/active_record/associations/builder/has_many.rb index a60cb4769a..7909b93622 100644 --- a/activerecord/lib/active_record/associations/builder/has_many.rb +++ b/activerecord/lib/active_record/associations/builder/has_many.rb @@ -8,7 +8,7 @@ module ActiveRecord::Associations::Builder super + [:primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache] end - def valid_dependent_options + def self.valid_dependent_options [:destroy, :delete_all, :nullify, :restrict_with_error, :restrict_with_exception] end end diff --git a/activerecord/lib/active_record/associations/builder/has_one.rb b/activerecord/lib/active_record/associations/builder/has_one.rb index accd29e5ef..a2509b5bae 100644 --- a/activerecord/lib/active_record/associations/builder/has_one.rb +++ b/activerecord/lib/active_record/associations/builder/has_one.rb @@ -10,14 +10,14 @@ module ActiveRecord::Associations::Builder valid end - def valid_dependent_options + def self.valid_dependent_options [:destroy, :delete, :nullify, :restrict_with_error, :restrict_with_exception] end private - def add_before_destroy_callbacks(model, name) - super unless options[:through] + def add_before_destroy_callbacks(model, reflection) + super unless reflection.options[:through] end end end -- cgit v1.2.3 From 743f1a9094c0b6f7b47a9dad211a6b2b77bdb85a Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 2 Oct 2013 15:08:18 -0700 Subject: add_before_destroy_callbacks doesn't depend on the instance, so push it to the class. --- .../lib/active_record/associations/builder/association.rb | 8 ++++---- activerecord/lib/active_record/associations/builder/has_one.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'activerecord/lib/active_record/associations/builder') diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb index e6da251550..dd2a6415b4 100644 --- a/activerecord/lib/active_record/associations/builder/association.rb +++ b/activerecord/lib/active_record/associations/builder/association.rb @@ -69,7 +69,7 @@ module ActiveRecord::Associations::Builder end def define_callbacks(model, reflection) - add_before_destroy_callbacks(model, reflection) if reflection.options[:dependent] + self.class.add_before_destroy_callbacks(model, reflection) if reflection.options[:dependent] Association.extensions.each do |extension| extension.build model, reflection end @@ -110,9 +110,9 @@ module ActiveRecord::Associations::Builder private - def add_before_destroy_callbacks(model, reflection) - unless self.class.valid_dependent_options.include? reflection.options[:dependent] - raise ArgumentError, "The :dependent option must be one of #{self.class.valid_dependent_options}, but is :#{reflection.options[:dependent]}" + def self.add_before_destroy_callbacks(model, reflection) + unless valid_dependent_options.include? reflection.options[:dependent] + raise ArgumentError, "The :dependent option must be one of #{valid_dependent_options}, but is :#{reflection.options[:dependent]}" end name = reflection.name diff --git a/activerecord/lib/active_record/associations/builder/has_one.rb b/activerecord/lib/active_record/associations/builder/has_one.rb index a2509b5bae..f359efd496 100644 --- a/activerecord/lib/active_record/associations/builder/has_one.rb +++ b/activerecord/lib/active_record/associations/builder/has_one.rb @@ -16,7 +16,7 @@ module ActiveRecord::Associations::Builder private - def add_before_destroy_callbacks(model, reflection) + def self.add_before_destroy_callbacks(model, reflection) super unless reflection.options[:through] end end -- cgit v1.2.3 From ea11af9568744a665f8ddc8f0cdca7407cc51d2b Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 2 Oct 2013 15:10:43 -0700 Subject: decouple belongs_to callback definition from the builder instance. All the information is on the reflection, so just get it there. --- activerecord/lib/active_record/associations/builder/belongs_to.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'activerecord/lib/active_record/associations/builder') diff --git a/activerecord/lib/active_record/associations/builder/belongs_to.rb b/activerecord/lib/active_record/associations/builder/belongs_to.rb index 1d9492a3bd..8d7ede1dbe 100644 --- a/activerecord/lib/active_record/associations/builder/belongs_to.rb +++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb @@ -14,8 +14,8 @@ module ActiveRecord::Associations::Builder def define_callbacks(model, reflection) super - add_counter_cache_callbacks(model, reflection) if options[:counter_cache] - add_touch_callbacks(model, reflection) if 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) @@ -117,8 +117,8 @@ module ActiveRecord::Associations::Builder def add_touch_callbacks(model, reflection) foreign_key = reflection.foreign_key - n = name - touch = options[:touch] + n = reflection.name + touch = reflection.options[:touch] callback = lambda { |record| BelongsTo.touch_record(record, foreign_key, n, touch) -- cgit v1.2.3 From 32bacb1ce80a06f328a0f32ca27c07d8417704bc Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 2 Oct 2013 15:11:47 -0700 Subject: cache the name and options on the stack --- .../lib/active_record/associations/builder/collection_association.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/associations/builder') diff --git a/activerecord/lib/active_record/associations/builder/collection_association.rb b/activerecord/lib/active_record/associations/builder/collection_association.rb index 38a70f3efd..d640446a6d 100644 --- a/activerecord/lib/active_record/associations/builder/collection_association.rb +++ b/activerecord/lib/active_record/associations/builder/collection_association.rb @@ -25,8 +25,10 @@ module ActiveRecord::Associations::Builder def define_callbacks(model, reflection) super + name = reflection.name + options = reflection.options CALLBACKS.each { |callback_name| - define_callback(model, callback_name, reflection.name, reflection.options) + define_callback(model, callback_name, name, options) } end -- cgit v1.2.3 From 07d522b1bee0cec428c332ac8b7099a737f7ea35 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 2 Oct 2013 15:12:32 -0700 Subject: get the name from the reflection --- .../lib/active_record/associations/builder/has_and_belongs_to_many.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/associations/builder') 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 55ec3bf4f1..abe6357185 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 @@ -10,7 +10,7 @@ module ActiveRecord::Associations::Builder def define_callbacks(model, reflection) super - name = self.name + name = reflection.name model.send(:include, Module.new { class_eval <<-RUBY, __FILE__, __LINE__ + 1 def destroy_associations -- cgit v1.2.3 From 73ee85f39dadb35e61269ab0f6bd23503268c37d Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 2 Oct 2013 15:19:33 -0700 Subject: push methods that don't depend on the instance to the class --- activerecord/lib/active_record/associations/builder/belongs_to.rb | 8 ++++---- .../active_record/associations/builder/collection_association.rb | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'activerecord/lib/active_record/associations/builder') diff --git a/activerecord/lib/active_record/associations/builder/belongs_to.rb b/activerecord/lib/active_record/associations/builder/belongs_to.rb index 8d7ede1dbe..6d590c8220 100644 --- a/activerecord/lib/active_record/associations/builder/belongs_to.rb +++ b/activerecord/lib/active_record/associations/builder/belongs_to.rb @@ -14,8 +14,8 @@ module ActiveRecord::Associations::Builder def define_callbacks(model, reflection) super - add_counter_cache_callbacks(model, reflection) if reflection.options[:counter_cache] - add_touch_callbacks(model, reflection) if reflection.options[:touch] + self.class.add_counter_cache_callbacks(model, reflection) if reflection.options[:counter_cache] + self.class.add_touch_callbacks(model, reflection) if reflection.options[:touch] end def define_accessors(mixin, reflection) @@ -70,7 +70,7 @@ module ActiveRecord::Associations::Builder end end - def add_counter_cache_callbacks(model, reflection) + def self.add_counter_cache_callbacks(model, reflection) cache_column = reflection.counter_cache_column model.after_create lambda { |record| @@ -115,7 +115,7 @@ module ActiveRecord::Associations::Builder end end - def add_touch_callbacks(model, reflection) + def self.add_touch_callbacks(model, reflection) foreign_key = reflection.foreign_key n = reflection.name touch = reflection.options[:touch] diff --git a/activerecord/lib/active_record/associations/builder/collection_association.rb b/activerecord/lib/active_record/associations/builder/collection_association.rb index d640446a6d..68f60a76b0 100644 --- a/activerecord/lib/active_record/associations/builder/collection_association.rb +++ b/activerecord/lib/active_record/associations/builder/collection_association.rb @@ -28,7 +28,7 @@ module ActiveRecord::Associations::Builder name = reflection.name options = reflection.options CALLBACKS.each { |callback_name| - define_callback(model, callback_name, name, options) + self.class.define_callback(model, callback_name, name, options) } end @@ -39,7 +39,7 @@ module ActiveRecord::Associations::Builder end end - def define_callback(model, callback_name, name, options) + def self.define_callback(model, callback_name, name, options) full_callback_name = "#{callback_name}_for_#{name}" # TODO : why do i need method_defined? I think its because of the inheritance chain -- cgit v1.2.3 From b86a4965b8532286430b7cd9b359a2574d745b92 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 2 Oct 2013 15:27:18 -0700 Subject: we can define callbacks without a builder instance --- activerecord/lib/active_record/associations/builder/association.rb | 6 +++--- activerecord/lib/active_record/associations/builder/belongs_to.rb | 6 +++--- .../active_record/associations/builder/collection_association.rb | 4 ++-- .../active_record/associations/builder/has_and_belongs_to_many.rb | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'activerecord/lib/active_record/associations/builder') 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 { -- cgit v1.2.3