diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-03-06 21:39:05 -0800 |
---|---|---|
committer | wycats <wycats@gmail.com> | 2010-03-06 21:41:13 -0800 |
commit | a424f199a9143e7ea451ba6f5e7dc54eb6103988 (patch) | |
tree | 003507405c1c7b155596e58c8b39f23675b3748a /activerecord | |
parent | 939291e8f2b68e11cde12f5f08886f8fca3ef2b2 (diff) | |
download | rails-a424f199a9143e7ea451ba6f5e7dc54eb6103988.tar.gz rails-a424f199a9143e7ea451ba6f5e7dc54eb6103988.tar.bz2 rails-a424f199a9143e7ea451ba6f5e7dc54eb6103988.zip |
drying up more code in associations.rb
Signed-off-by: wycats <wycats@gmail.com>
Diffstat (limited to 'activerecord')
-rwxr-xr-x | activerecord/lib/active_record/associations.rb | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 86edfc386d..e1a9c54e5d 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -1561,24 +1561,18 @@ module ActiveRecord def configure_dependency_for_belongs_to(reflection) if reflection.options.include?(:dependent) - case reflection.options[:dependent] - when :destroy - method_name = "belongs_to_dependent_destroy_for_#{reflection.name}".to_sym - define_method(method_name) do - association = send(reflection.name) - association.destroy unless association.nil? - end - after_destroy method_name - when :delete - method_name = "belongs_to_dependent_delete_for_#{reflection.name}".to_sym - define_method(method_name) do - association = send(reflection.name) - association.delete unless association.nil? - end - after_destroy method_name - else - raise ArgumentError, "The :dependent option expects either :destroy or :delete (#{reflection.options[:dependent].inspect})" + name = reflection.options[:dependent] + + unless [:destroy, :delete].include?(name) + raise ArgumentError, "The :dependent option expects either :destroy or :delete (#{reflection.options[:dependent].inspect})" + end + + method_name = :"belongs_to_dependent_#{name}_for_#{reflection.name}" + define_method(method_name) do + association = send(reflection.name) + association.destroy unless association.nil? end + after_destroy method_name end end |