views:

2369

answers:

3

Hello

I am running Rails 2.0.2 and am unable to use :dependent => :delete in my AR associations

 has_many :items, :dependent => :delete

I am given this error.

  The :dependent option expects either :destroy, :delete_all, or :nullify (:delete)

I have be unable to find the documentation for :delete_all to see if it does what I want. Is it basically the same thing as delete? Was :delete recently added to Rails and is not in the version I am using?

Thank you

A: 

There is no mention of :delete in the documentation of the current stable version 2.3.2:

Objects will be in addition destroyed if they’re associated with :dependent => :destroy, and deleted if they’re associated with :dependent => :delete_all.

http://apidock.com/rails/ActiveRecord/Associations/ClassMethods/has_many

Adam Byrtek
+1  A: 

Here's the relevant documentation for Rails 2.0.2:

if set to :destroy all the associated objects are destroyed 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.

railsbrain.com is a good place to find docs specific to a certain version of Rails.

Sarah Mei
A: 

What's the default action? Does it work as if you set it to nullify but trying to save the object? Will objects which are validating the existance of the destroyed object dissappear?

Floyd