Я только что создал поле 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, и я не знаю, как сообщить ему, что для has_many: через объединение.
belongs_to :user, :counter_cache => :received_likes