Hi guys, I have a problem with counter cache on the rails trunk version. I have the following test case: doc = Document.new assert doc.bookmarks.create() assert doc.save! assert doc.reload assert_equal 1, doc.bookmarks_count But doc.save! sets the bookmarks_count column on document to 0 (after it has been raised by bookmarks.create) the following queries can be found in log: 1. SELECT * FROM documents WHERE (documents.id = 1) 2. UPDATE documents SET bookmarks_count = bookmarks_count + 1 WHERE (id = 1) 3. COMMIT 4. BEGIN 5. SELECT * FROM bookmarks WHERE (bookmarks.bookmarkable_id = 1 AND bookmarks.bookmarkable_type = ''Document'') 6. UPDATE documents SET `content` = NULL, `bookmarks_count` = 0, `name` = NULL WHERE id = 1 7. COMMIT quite frustrating... :S My models: -- Document.rb: class Document < ActiveRecord::Base has_many :bookmarks, :as => :bookmarkable, :dependent => :destroy end -- Bookmark.rb: class Bookmark < ActiveRecord::Base # associations belongs_to :bookmarkable, :polymorphic => true, :counter_cache => "bookmarks_count" end --~--~---------~--~----~------------~-------~--~----~ 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''ve experienced the same problem. There is a ticket already created in the Rails Trac. Hopeful this post will escalate the ticket''s priority. http://dev.rubyonrails.org/ticket/6896 --~--~---------~--~----~------------~-------~--~----~ 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''ve experienced the same problem. There is a ticket already created in > the Rails Trac. Hopeful this post will escalate the ticket''s priority. > > http://dev.rubyonrails.org/ticket/6896This is a fairly intrusive change to be adding late in the piece. The attr_readonly fix is a nice enhancement, and can perhaps be applied more broadly. However it probably needs a little more thought: * Should read only attributes have mutators at all? * If they do, in what conditions should they raise exceptions vs updating the attributes hash * What other attributes in the system should be attr_readonly (inheritance_column being the first case which jumps to mind[1]) Etc. I like where it''s going, but I can''t really see it happening so close to RC2. -- Cheers Koz [1] No, you''re wrong, you don''t need .type= ;) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---