Skip to content

Commit

Permalink
use the information on the reflection to determine whether callbacks …
Browse files Browse the repository at this point in the history
…should be added
  • Loading branch information
tenderlove committed Oct 2, 2013
1 parent 640c15b commit a88a5d7
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def define_extensions(model)
end end


def define_callbacks(model, reflection) 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| Association.extensions.each do |extension|
extension.build model, reflection extension.build model, reflection
end end
Expand Down Expand Up @@ -110,11 +110,12 @@ def valid_dependent_options


private private


def add_before_destroy_callbacks(model, name) def add_before_destroy_callbacks(model, reflection)
unless valid_dependent_options.include? options[:dependent] unless valid_dependent_options.include? reflection.options[:dependent]
raise ArgumentError, "The :dependent option must be one of #{valid_dependent_options}, but is :#{options[:dependent]}" raise ArgumentError, "The :dependent option must be one of #{valid_dependent_options}, but is :#{reflection.options[:dependent]}"
end end


name = reflection.name
model.before_destroy lambda { |o| o.association(name).handle_dependency } model.before_destroy lambda { |o| o.association(name).handle_dependency }
end end
end end
Expand Down

0 comments on commit a88a5d7

Please sign in to comment.