aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-08-29 17:06:27 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-08-29 17:06:27 +0000
commit3704088ebde5ef074d186bff0d380858a9a01055 (patch)
treecae788b86554be381aff084f7b3da48a4fc428b4 /activerecord/lib/active_record
parent92f1e26a1c9f48ac575414976012d6dfa127bdac (diff)
downloadrails-3704088ebde5ef074d186bff0d380858a9a01055.tar.gz
rails-3704088ebde5ef074d186bff0d380858a9a01055.tar.bz2
rails-3704088ebde5ef074d186bff0d380858a9a01055.zip
has_one supports the :dependent => :delete option which skips the typical callback chain and deletes the associated object directly from the database. Closes #5927.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4848 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 8f45ce5428..65db5f9b23 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -570,8 +570,9 @@ module ActiveRecord
# sql fragment, such as "rank = 5".
# * <tt>:order</tt> - specify the order from which the associated object will be picked at the top. Specified as
# an "ORDER BY" sql fragment, such as "last_name, first_name DESC"
- # * <tt>:dependent</tt> - if set to :destroy (or true) all the associated objects are destroyed when this object is. Also,
- # association is assigned.
+ # * <tt>:dependent</tt> - if set to :destroy (or true) the associated object is destroyed when this object is. If set to
+ # :delete the associated object is deleted *without* calling its destroy method. If set to :nullify the associated
+ # object's foreign key is set to NULL. Also, association is assigned.
# * <tt>:foreign_key</tt> - specify the foreign key used for the association. By default this is guessed to be the name
# of this class in lower-case and "_id" suffixed. So a +Person+ class that makes a has_one association will use "person_id"
# as the default foreign_key.
@@ -1020,12 +1021,14 @@ module ActiveRecord
case reflection.options[:dependent]
when :destroy, true
module_eval "before_destroy '#{reflection.name}.destroy unless #{reflection.name}.nil?'"
+ when :delete
+ module_eval "before_destroy '#{reflection.class_name}.delete(#{reflection.name}.id) unless #{reflection.name}.nil?'"
when :nullify
module_eval "before_destroy '#{reflection.name}.update_attribute(\"#{reflection.primary_key_name}\", nil)'"
when nil, false
# pass
else
- raise ArgumentError, "The :dependent option expects either :destroy or :nullify."
+ raise ArgumentError, "The :dependent option expects either :destroy, :delete or :nullify."
end
end