订购嵌套的has_many:通过关联计数

我正在尝试按照与特定组的用户关联的降序频率顺序对标签进行排序。 (ActiveRecord和Rails 3.2 – 如果有帮助我也安装了Squeel!)

用户有标签,组有用户。 因此,组通过用户具有标签。

class Group < ActiveRecord::Base has_many :users_groups # join table has_many :users, through: :users_groups has_many :tags, through: :users class User < ActiveRecord::Base has_many :users_groups # join table has_many :groups, through: :users_groups has_many :taggings # join table has_many :tags, through: taggings class Tag < ActiveRecord::Base has_many :taggings # join table has_many :users, through: taggings 

史蒂夫[ https://stackoverflow.com/a/11624005/59195 ]和Amol [ https://stackoverflow.com/a/10958311/59195 ]的这些答案最接近我正在尝试做的事 – 虽然我想要按照作为组成员的用户使用/关联的频率对标签进行排序,而不是所有用户。

有任何想法吗? 谢谢您的帮助!