Ruby on Rails Saturday, January 10, 2015

class User < ActiveRecord::Base
  has_many :likes
  has_many :liked_things, :through => :likes
end

class Thing < ActiveRecord::Base
  has_many :likes
  has_many :liked_by_users, :through => :likes
end

class Like < ActiveRecord::Base
  belongs_to :user
  belongs_to :shot
end

This is my setup, and I have a `likes_count` column on Things Table. Is there any way to keep that count updating using counter_cache ? I got it working counter_cache on has_many association but failing to do same with has_many through association.


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/b1fc2e26-ebfe-448a-8f40-61d0b7523e13%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment