diff options
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations/builder/association.rb | 17 | ||||
-rw-r--r-- | activerecord/lib/active_record/associations/builder/has_one.rb | 10 |
2 files changed, 15 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/associations/builder/association.rb b/activerecord/lib/active_record/associations/builder/association.rb index b20347a52a..ef397fdb52 100644 --- a/activerecord/lib/active_record/associations/builder/association.rb +++ b/activerecord/lib/active_record/associations/builder/association.rb @@ -53,7 +53,6 @@ module ActiveRecord::Associations::Builder end def build - configure_dependency if options[:dependent] ActiveRecord::Reflection.create(macro, name, scope, options, model) end @@ -70,6 +69,7 @@ module ActiveRecord::Associations::Builder end def define_callbacks(model, reflection) + add_before_destroy_callbacks(model, name) if options[:dependent] Association.extensions.each do |extension| extension.build model, reflection end @@ -103,17 +103,18 @@ module ActiveRecord::Associations::Builder CODE end - def configure_dependency + def valid_dependent_options + raise NotImplementedError + end + + 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]}" end - n = name - model.before_destroy lambda { |o| o.association(n).handle_dependency } - end - - def valid_dependent_options - raise NotImplementedError + model.before_destroy lambda { |o| o.association(name).handle_dependency } end 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 2406437a07..62d454ce55 100644 --- a/activerecord/lib/active_record/associations/builder/has_one.rb +++ b/activerecord/lib/active_record/associations/builder/has_one.rb @@ -14,12 +14,14 @@ module ActiveRecord::Associations::Builder !options[:through] end - def configure_dependency - super unless options[:through] - end - def 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] + end end end |