Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 2939

Show
Ignore:
Timestamp:
11/08/05 08:41:34 (4 years ago)
Author:
bitsweat
Message:

Deprecate the old, confusing :exclusively_dependent option in favor of :dependent => :delete_all.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r2935 r2939  
    11*SVN* 
     2 
     3* Deprecate the old, confusing :exclusively_dependent option in favor of :dependent => :delete_all.  [Jeremy Kemper] 
    24 
    35* More compatible Oracle column reflection.  #2771 [Ryan Davis <ryand-ruby@zenspider.com>, Michael Schoen <schoenm@earthlink.net>] 
  • trunk/activerecord/lib/active_record/associations.rb

    r2898 r2939  
    312312      #   as the default foreign_key. 
    313313      # * <tt>:dependent</tt>   - if set to :destroy (or true) all the associated objects are destroyed 
    314       #   alongside this object. Also accepts :nullify which will set the associated object's foreign key 
    315       #   field to NULL. 
     314      #   alongside this object by calling their destroy method.  If set to :delete_all all associated 
     315      #   objects are deleted *without* calling their destroy method.  If set to :nullify all associated 
     316      #   objects' foreign keys are set to NULL *without* calling their save callbacks. 
    316317      #   May not be set if :exclusively_dependent is also set. 
    317       # * <tt>:exclusively_dependent</tt>   - if set to true all the associated object are deleted in one SQL statement without having their 
     318      # * <tt>:exclusively_dependent</tt>   - Deprecated; equivalent to :dependent => :delete_all. If set to true all 
     319      #   the associated object are deleted in one SQL statement without having their 
    318320      #   before_destroy callback run. This should only be used on associations that depend solely on this class and don't need to do any 
    319321      #   clean-up in before_destroy. The upside is that it's much faster, especially if there's a counter_cache involved. 
     
    351353 
    352354        raise ArgumentError, ':dependent and :exclusively_dependent are mutually exclusive options.  You may specify one or the other.' if options[:dependent] and options[:exclusively_dependent] 
    353            
     355 
     356        if options[:exclusively_dependent] 
     357          options[:dependent] = :delete_all 
     358          #warn "The :exclusively_dependent option is deprecated.  Please use :dependent => :delete_all instead.") 
     359        end 
     360 
    354361        # See HasManyAssociation#delete_records.  Dependent associations 
    355362        # delete children, otherwise foreign key is set to NULL. 
     
    357364          when :destroy, true   
    358365            module_eval "before_destroy '#{association_name}.each { |o| o.destroy }'" 
     366          when :delete_all 
     367            module_eval "before_destroy { |record| #{association_class_name}.delete_all(%(#{association_class_primary_key_name} = \#{record.quoted_id})) }" 
    359368          when :nullify 
    360369            module_eval "before_destroy { |record| #{association_class_name}.update_all(%(#{association_class_primary_key_name} = NULL),  %(#{association_class_primary_key_name} = \#{record.quoted_id})) }" 
     
    362371            # pass 
    363372          else 
    364             raise ArgumentError, 'The :dependent option expects either true, :destroy or :nullify'  
    365         end    
    366          
    367         if options[:exclusively_dependent] 
    368           module_eval "before_destroy { |record| #{association_class_name}.delete_all(%(#{association_class_primary_key_name} = \#{record.quoted_id})) }" 
    369         end 
     373            raise ArgumentError, 'The :dependent option expects either true, :destroy, :delete_all, or :nullify'  
     374        end 
     375 
    370376 
    371377        add_multiple_associated_save_callbacks(association_name)