Hi, 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? Thanks! -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 2 April 2012 17:25, Serafino Picozzi <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi, > > 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?You have not told us what is the reverse association between MenuItem and Page. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mon, Apr 2, 2012 at 3:10 PM, Serafino Picozzi <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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 bothWhat makes you think that? -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hassan Schroeder wrote in post #1054715:> On Mon, Apr 2, 2012 at 3:10 PM, Serafino Picozzi <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > 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? > > -- > Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > http://about.me/hassanschroeder > twitter: @hassanI 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 -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mon, Apr 2, 2012 at 3:48 PM, Serafino Picozzi <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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 recordThen 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-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mon, Apr 2, 2012 at 4:19 PM, Serafino Picozzi <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Probably then it''s related to the awesome_nested_set plugin...Well, I just added awesome_nested_set (as a gem) to my little test app, and it didn''t have any effect on using :dependent => :destroy. You might want to build your own separate test app and add things in one by one to isolate the problem. HTH, -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Apr 2, 2012, at 9:06 PM, Hassan Schroeder wrote:> On Mon, Apr 2, 2012 at 4:19 PM, Serafino Picozzi <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Probably then it''s related to the awesome_nested_set plugin... > > Well, I just added awesome_nested_set (as a gem) to my little test > app, and it didn''t have any effect on using :dependent => :destroy. > > You might want to build your own separate test app and add things > in one by one to isolate the problem.Ditto for CanCan -- no issues here with nested records and delete options. Walter> > HTH, > -- > Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 2 April 2012 23:10, Serafino Picozzi <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> There is no reverse, it''s a regular has_one belongs_to association.The reverse relation is then MenuItem has_one Page. That is what you had not told us. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.