Hi guys, Right now when using counter_cache and using delete to destroy associated records, for example: @post.comments.delete(comment) the cache column is not being updated. This was reported in ticket #1196, i confirmed it was actually a bug, and made a patch to fix this with tests for has_many and HMT associations. It''s working if you use record.destroy, but it should also be updated when using delete. Ticket/Patch: http://rails.lighthouseapp.com/projects/8994/tickets/1196-counter_cache-not-decrementing-on-delete --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
I believe that that is the expected behavior. Delete does not call any callbacks either and it does not destroy associated records in has_many relationships. I guess it could be a rails gotcha.. HTH, Jason On Dec 6, 10:06 am, "Emilio Tagua" <milo...@gmail.com> wrote:> Hi guys, > Right now when using counter_cache and using delete to destroy associated > records, for example: @post.comments.delete(comment) the cache column is not > being updated. > > This was reported in ticket #1196, i confirmed it was actually a bug, and > made a patch to fix this with tests for has_many and HMT associations. > > It''s working if you use record.destroy, but it should also be updated when > using delete. > > Ticket/Patch:http://rails.lighthouseapp.com/projects/8994/tickets/1196-counter_cac...--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
On Mon, Dec 8, 2008 at 3:17 AM, jasoo24 <jasoo24@gmail.com> wrote:> > I believe that that is the expected behavior. Delete does not call any > callbacks either and it does not destroy associated records in > has_many relationships. I guess it could be a rails gotcha.. >Hey Jason, Delete method destroy the associated records on HM and HMT associations, that is what the implementation of delete does in association_collection.rb, and if you look at the code in the delete method callbacks are called too. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---