How do I optimize this rails scope to get the correct results?


I would like to show my 5 most active tags. (most used)

I did the following but I have a feeling the results are not correct.


class Tag < ApplicationRecord

has_many :taggings,  :dependent => :delete_all
has_many :posts, through: :taggings
scope :top5, ->  {",, count( as count").joins(:taggings).group("").limit(5).order('count DESC')

Does this seem correct? I am using pg. Thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.