I have two models, Page and MenuItem, where Page belongs_to MenuItem .
When I delete a page I need to delete also its MenuItem, and vice versa.
The problema is that I can't put a :dependent => :destroy on both
relations because (obviously) this gives an error.
Is there a clean way to solve this?
There is no reverse, it's a regular has_one belongs_to association. i
just wanto to be able to delete both records either by deleting a page
from the pages_controller or by deleting a menu_item from the
menu_items_controller. in both cases both the page and the menu item
need to be deleted like a dependent association, but it's impossible to
put dependent => destroy on both
Then you have a different problem, because it works for me
e.g.
class Ship < ActiveRecord::Base
has_one :captain, :dependent => :destroy
end
class Captain < ActiveRecord::Base
belongs_to :ship, :dependent => :destroy
end
Calling 'destroy' on either gets rid of both, as expected.
Probably then it's related to the awesome_nested_set plugin... This
sucks it's already the second plugin I'm trying to use (the other is
cancan) that breaks some core functionality
First of all thank you, I didn't expect you to go that far testing. The
point however is that the problem is solved if i remove
awesome_nested_set from the model