Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does :dependent => :restrict throw an error?

This question Check all associations before destroy in rails suggests using :dependent => :restrict.

Why do I get ArgumentError: Unknown key(s): dependent?

Does this work with has_and_belongs_to_many?

Why is there no mention in the docs? http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html

Was it introduced after 3.0.7?

like image 795
B Seven Avatar asked Mar 18 '26 10:03

B Seven


1 Answers

:dependent cannot be used with has_and_belongs_to_many. The docs you link to list the association methods that accept it: has_many, has_one and belongs_to.

You could add a before_remove hook and do your dependent check manually.

like image 144
Michael Slade Avatar answered Mar 20 '26 03:03

Michael Slade



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!