Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails has_one remove link

Is the only way to destroy an association of a has_one and belongs_to by setting the FK to nil on the belongs_to object?

like image 477
Michael Avatar asked Oct 27 '25 18:10

Michael


2 Answers

Doesn't setting @obj1.obj2 = nil work?

But this doesn't delete the belongs_to record. If you want to do it you need to do @obj1.obj2.delete

like image 68
Syed Aslam Avatar answered Oct 30 '25 08:10

Syed Aslam


Since I remenber, once you set drop in cascade, you just have to delete the object and it deletes all dependencies.

Hope this helps, Cheers

like image 42
Ron Avatar answered Oct 30 '25 09:10

Ron



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!