Ruby on Rails Monday, April 2, 2012

On Mon, Apr 2, 2012 at 3:48 PM, Serafino Picozzi <lists@ruby-forum.com> wrote:

>>> 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
>>
>> What makes you think that?

> I tried. With dependent destroy on both the belongs_to and has_one when
> i delete one i get an error about not finding the other record

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.

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
http://about.me/hassanschroeder
twitter: @hassan

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment