aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2005-11-08 08:41:34 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2005-11-08 08:41:34 +0000
commitc54b51fa7e6fd51f89cd74c9b2b2f144f2229ee9 (patch)
treea3d9ca9df17f7a95df45a6d022641c23156b693f /activerecord
parent85baf07be82b7e4313c6eeeebdd365a6f45fd405 (diff)
downloadrails-c54b51fa7e6fd51f89cd74c9b2b2f144f2229ee9.tar.gz
rails-c54b51fa7e6fd51f89cd74c9b2b2f144f2229ee9.tar.bz2
rails-c54b51fa7e6fd51f89cd74c9b2b2f144f2229ee9.zip
Deprecate the old, confusing :exclusively_dependent option in favor of :dependent => :delete_all.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2939 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/associations.rb24
2 files changed, 17 insertions, 9 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 63672ff71a..32d9ddda0b 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Deprecate the old, confusing :exclusively_dependent option in favor of :dependent => :delete_all. [Jeremy Kemper]
+
* More compatible Oracle column reflection. #2771 [Ryan Davis <ryand-ruby@zenspider.com>, Michael Schoen <schoenm@earthlink.net>]
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index ff6775e027..077245559a 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -311,10 +311,12 @@ module ActiveRecord
# of this class in lower-case and "_id" suffixed. So a +Person+ class that makes a has_many association will use "person_id"
# as the default foreign_key.
# * <tt>:dependent</tt> - if set to :destroy (or true) all the associated objects are destroyed
- # alongside this object. Also accepts :nullify which will set the associated object's foreign key
- # field to NULL.
+ # alongside this object by calling their destroy method. If set to :delete_all all associated
+ # objects are deleted *without* calling their destroy method. If set to :nullify all associated
+ # objects' foreign keys are set to NULL *without* calling their save callbacks.
# May not be set if :exclusively_dependent is also set.
- # * <tt>:exclusively_dependent</tt> - if set to true all the associated object are deleted in one SQL statement without having their
+ # * <tt>:exclusively_dependent</tt> - Deprecated; equivalent to :dependent => :delete_all. If set to true all
+ # the associated object are deleted in one SQL statement without having their
# before_destroy callback run. This should only be used on associations that depend solely on this class and don't need to do any
# clean-up in before_destroy. The upside is that it's much faster, especially if there's a counter_cache involved.
# May not be set if :dependent is also set.
@@ -350,24 +352,28 @@ module ActiveRecord
require_association_class(association_class_name)
raise ArgumentError, ':dependent and :exclusively_dependent are mutually exclusive options. You may specify one or the other.' if options[:dependent] and options[:exclusively_dependent]
-
+
+ if options[:exclusively_dependent]
+ options[:dependent] = :delete_all
+ #warn "The :exclusively_dependent option is deprecated. Please use :dependent => :delete_all instead.")
+ end
+
# See HasManyAssociation#delete_records. Dependent associations
# delete children, otherwise foreign key is set to NULL.
case options[:dependent]
when :destroy, true
module_eval "before_destroy '#{association_name}.each { |o| o.destroy }'"
+ when :delete_all
+ module_eval "before_destroy { |record| #{association_class_name}.delete_all(%(#{association_class_primary_key_name} = \#{record.quoted_id})) }"
when :nullify
module_eval "before_destroy { |record| #{association_class_name}.update_all(%(#{association_class_primary_key_name} = NULL), %(#{association_class_primary_key_name} = \#{record.quoted_id})) }"
when nil, false
# pass
else
- raise ArgumentError, 'The :dependent option expects either true, :destroy or :nullify'
- end
-
- if options[:exclusively_dependent]
- module_eval "before_destroy { |record| #{association_class_name}.delete_all(%(#{association_class_primary_key_name} = \#{record.quoted_id})) }"
+ raise ArgumentError, 'The :dependent option expects either true, :destroy, :delete_all, or :nullify'
end
+
add_multiple_associated_save_callbacks(association_name)
add_association_callbacks(association_name, options)