天天看點

cache_count

ruby 代碼

  1. #thingsuser.rb   
  2. class Thingsuser < ActiveRecord::Base   
  3.     belongs_to :user  
  4.     belongs_to :thing, :counter_cache => true     
  5. end  

ruby 代碼

  1. #user.rb   
  2.   has_many :thingsusers  
  3.   has_many :things,:through=>:thingsusers,:dependent =>:destroy    

ruby 代碼

  1. #thing.rb   
  2.   has_many :thingsusers  
  3.   has_many :users,  :through => :thingsusers  

table.column:thingsusers_count