diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-02 15:02:48 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-10-02 15:28:49 -0700 |
commit | a88a5d73704307f9fcd1187ddeba0bbfd7b5968c (patch) | |
tree | bf5652a01efcda0c1adde2bc2583a0be092baab2 /activerecord/lib | |
parent | 640c15bab8d63e9303e35f5e046d59027b9e65d0 (diff) | |
download | rails-a88a5d73704307f9fcd1187ddeba0bbfd7b5968c.tar.gz rails-a88a5d73704307f9fcd1187ddeba0bbfd7b5968c.tar.bz2 rails-a88a5d73704307f9fcd1187ddeba0bbfd7b5968c.zip |
use the information on the reflection to determine whether callbacks should be added
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/builder/association.rb | 9 |
1 files changed, 5 insertions, 4 deletions
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 |