Report abuse


			
Tag.find(:all, 
      :select => 'tags.*, count(*) as tag_popularity',
      :limit => options[:limit] || 10,
      :joins => "JOIN taggings ON taggings.tag_id = tags.id
                 JOIN groups   ON groups.id       = taggings.taggable_id
                              AND 'Group'         = taggings.taggable_type",
      :conditions => options[:conditions],
      :group => "taggings.tag_id",
      :order => "groups.users_count DESC, tag_popularity DESC"
    )

# I get the right records from the DB, but in the wrong order - the tag objects are ordered
# by ID as opposed to the order clause, "groups.users_count DESC, tag_popularity DESC"
# I'm just fumbling around with sql, what am I doing wrong?