Skip to content
Browse files

use the information on the reflection to determine whether callbacks …

…should be added
  • Loading branch information...
1 parent 640c15b commit a88a5d73704307f9fcd1187ddeba0bbfd7b5968c @tenderlove tenderlove committed
Showing with 5 additions and 4 deletions.
  1. +5 −4 activerecord/lib/active_record/associations/builder/association.rb
View
9 activerecord/lib/active_record/associations/builder/association.rb
@@ -69,7 +69,7 @@ def define_extensions(model)
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 @@ def valid_dependent_options
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

0 comments on commit a88a5d7

Please sign in to comment.
Something went wrong with that request. Please try again.