Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails :dependent and :delete

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?

like image 490
stellard Avatar asked Aug 25 '26 12:08

stellard


2 Answers

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.

like image 89
Sarah Mei Avatar answered Aug 28 '26 03:08

Sarah Mei


Default action is "do nothing". Objects remain orphaned, nothing is deleted, destroyed or nullified.

like image 42
Alexander Zubkov Avatar answered Aug 28 '26 02:08

Alexander Zubkov