Check the SQL generated in the log. I''m noticing that the memory
version of the has_may record is not having its cache value being
updated, even when a "parent.child.create" is executed in a 1.2.2
rails. I''ll wager your code is triggering the SQL update of the
cache counter increment, but that the update without a reload is
overwriting the counter cache with the pre-creation value.
I''ll wager that the increment SQL was fired off, but that the old
value of the cache got rewritten during the update. A work-around
might be to reload the Proposal record before the update (yick!)
On Feb 14, 2007, at 1:30 PM, Kad Kerforn wrote:
>
> I am trying to use the counter_cache but it''s not updated...
>
> class Proposal < ActiveRecord::Base
> has_many :ratings, :dependent => :destroy
>
> (I have defined a ratings_count column (default value 0) in my
> proposals
> table)
>
> class Rating < ActiveRecord::Base
> belongs_to :user, :foreign_key => ''user_id''
> belongs_to :proposal, :foreign_key =>
> ''proposal_id'', :counter_cache =>
> true
>
> proposal_controller
>
> def add_new_rating
> ..
> @proposal = Proposal.find_by_id(params[:id].to_i)
> @proposal.ratings.create(:user => current_user, :comment => @comment,
> :value => @notation)
> @ proposal.update_attribute(:total_value , @total_value)
>
> the rating record is correctly created...
> the proposal record total_value attribute is correctly updated,
> but the
> counter ''ratings_count'' is not incremented
>
> --
> 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
-~----------~----~----~----~------~----~------~--~---