【发布时间】:2011-07-12 12:43:03
【问题描述】:
我刚刚创建了一个 counter_cache 字段,控制器看起来像这样。
@users = User.where(:sex => 2).order('received_likes_count')
User.rb 中的关联是
has_many :received_likes, :through => :attachments, :source => :likes, :dependent => :destroy
问题是 counter_cache 在 Like.rb 的 belongs_to 中声明,我不知道如何告诉它是为了 has_many :through 关联。
belongs_to :user, :counter_cache => :received_likes
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3