All, Rails 1.1.6 Win XP MS SQL Server (ODBC mode) I have the following class: class Document < ActiveRecord::Base has_many :images, :dependent => :delete_all has_many :stylesheets, :dependent => :delete_all In one of my controllers, I do: Document.destroy(valid_doc_id) and _no deletes_ are performed against my database, which is clearly wrong. If, however, I use script/console to do the same exact destroy call with the same id, the cascaded delete works just fine. I can hand code the cascaded delete, of course, but would like for :dependent => :delete_all to work as advertised. I know that it''s a long shot, but has anyone seen anything like this? Thanks, Wes -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
If I replace the call to the AR Base class method destroy with a call to the instance method destroy on that particular object, then the deletes appear to work correctly. That''s strange - any ideas? WG -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I''m having similar problems with :dependent => :destroy not destroying or deleting the dependent records. I''m having to just call association.clear in the after_destroy. Oddly, using association.clear in the before_destroy isn''t working for me either. It feels like there''s something going on preventing the association#destroy to fail but I don''t have time to spend trying to figure it out this time. You''re not alone on this though. RSL On 4/16/07, Wes Gamble <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > If I replace the call to the AR Base class method destroy with a call to > the instance method destroy on that particular object, then the deletes > appear to work correctly. > > That''s strange - any ideas? > > WG > > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
This seems like a reasonable idea. However, the fact that this object is frozen when you do a "destroy" on it keeps me from building a new one. So I have current_job.document, and I call current_job.document.destroy and then I can''t call current_job.build_document (I get a "can''t modify frozen hash" error). Frankly, I don''t understand why this happens - I''m not trying to modify the original document object, I''m trying to replace it with a whole different one. In general, it appears that once you have an association, you can''t destroy it and then expect to be able to replace it with another object. What''s up with that? Wes -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I must be missing something because it doesn''t seem reasonable to me that :dependent => :destroy wouldn''t be allowed to destroy the associated object. I must be missing something. RSL On 4/17/07, Wes Gamble <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > This seems like a reasonable idea. However, the fact that this object > is frozen when you do a "destroy" on it keeps me from building a new > one. > > So I have current_job.document, and I call current_job.document.destroy > and then I can''t call current_job.build_document (I get a "can''t modify > frozen hash" error). > > Frankly, I don''t understand why this happens - I''m not trying to modify > the original document object, I''m trying to replace it with a whole > different one. > > In general, it appears that once you have an association, you can''t > destroy it and then expect to be able to replace it with another object. > What''s up with that? > > Wes > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The destroy is allowed to happen but then you can''t replace the object -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I feel really stupid right now but obviously I''ve missed something. I don''t see that you [or I] are trying to replace any objects but destroy them. Sorry for being so thick about this but I''m honestly confused. I presumed that the problem was some kind of reference somewhere that I did wrong and because it couldn''t clear, the associated object never deletes. RSL On 4/17/07, Wes Gamble <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > The destroy is allowed to happen but then you can''t replace the object > > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You and I have the same problem vis a vis deleting and I am also calling .clear explicitly on the child objects. I too do not know why this is necessary. My _additional_ issue is that once I do the destroy on the child object, I cannot then create a new child object because the reference is frozen. So I''m complaining about that :). Buy that? Wes -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Gotcha. I _thought_ I was missing someething. :) On 4/18/07, Wes Gamble <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > You and I have the same problem vis a vis deleting and I am also calling > .clear explicitly on the child objects. I too do not know why this is > necessary. > > My _additional_ issue is that once I do the destroy on the child object, > I cannot then create a new child object because the reference is frozen. > So I''m complaining about that :). > > Buy that? > > Wes > > > > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Someone suggested that I reload the current_job model variable using current_job.reload and then perhaps I can do current_job.build_document(...) Anyone know if this is correct? WG -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
This works. current_job.document.destroy current_job.reload current_job.build_document Sweet. Wes -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---