Hi All, I''m using a counter_cache, which I believe I''m doing correctly because I can see this SQL query being executed in the development.log file: UPDATE gifts SET bookmarks_count = bookmarks_count + 1 WHERE (id = 276) However, in the gifts table, the bookmarks_count field isn''t incremented (it''s zero). If I literally copy and paste that query into the MySQL Query browser, it works and increments the value. Does anyone have any idea how that could happen? Thanks! Tom -- Posted via http://www.ruby-forum.com/.
Tom Lianza <tlianza@gmail.com> writes:> Hi All, > > I''m using a counter_cache, which I believe I''m doing correctly because I > can see this SQL query being executed in the development.log file: > > UPDATE gifts SET bookmarks_count = bookmarks_count + 1 WHERE (id = 276) > > However, in the gifts table, the bookmarks_count field isn''t incremented > (it''s zero). If I literally copy and paste that query into the MySQL > Query browser, it works and increments the value. > > Does anyone have any idea how that could happen? >Make sure the transaction is being committed and not rolled back. Cheers, -- Surendra Singhi http://ssinghi.kreeti.com, http://www.kreeti.com Read my blog at: http://cuttingtheredtape.blogspot.com/ ,---- | WHY SHOULD WE SAVE TIGER? | Ans: Saving the tiger means saving mankind.. | | Help http://pudang.tripod.com/ | or https://secure.worldwildlife.org/forms/tiger_appeal_1.cfm `----
Based on what I''ve been reading, it sounds like counter caches are horribly broken and unreliable. Anytime you try and save an object, it overwrites the counter cache with zero. http://dev.rubyonrails.org/ticket/5050 Also, rails seems to be finicky about how you associate things so the counter cache gets set (not that it matters, since it''s just going to be overwritten): http://lists.rubyonrails.org/pipermail/rails/2006-March/027450.html So, that''s kind of a bummer, because I think it''s a fairly important feature. If anyone has had any sucess with them, I''d love to hear about it. -- Posted via http://www.ruby-forum.com/.
Seemingly Similar Threads
- Thread.new with ActiveRecord under Mongrel vs. FastCGI
- Strategies for updating multiple parts of the page with AJAX
- Facebooker::Session::SessionExpired (Session key invalid or no longer valid)
- counter_cache, has_many and belongs_to
- acts_as_tree counter_cache