自己結合関連付けの列にカウンター キャッシュを追加しようとしています。User と follows の 2 つのモデルがあります。ユーザーには、ユーザー テーブル自体からのフォロワーとフォロワーがいます。
User.rb
has_many :followings
has_many :followers, :through => :followings
has_many :followees, :through => :followings
Following.rb
class Following < ActiveRecord::Base
attr_accessible :followee_id, :follower_id
belongs_to :follower, :class_name => "User"
belongs_to :followee, :class_name => "User"
end
と にカウンター キャッシュを追加したいと思いfollowerますfollowees。テーブルに列がありfollowers_countます。followees_countuser
私は試した
belongs_to :follower, :class_name => "User" , :counter_cache => true
しかし、これは user テーブルにデータを返しません。どんな助けでも大歓迎です。