Created
April 5, 2009 22:00
-
-
Save joshuaclayton/90557 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tag.class_eval do | |
default_scope :joins => :taggings | |
named_scope :popular, lambda {{ | |
:select => "#{Tag.quoted_table_name}.*, COUNT(*) AS popularity", | |
:group => "#{Tagging.quoted_table_name}.tag_id", | |
:order => "popularity DESC" | |
}} | |
named_scope :on, lambda {|klass| { | |
:joins => "INNER JOIN #{klass.quoted_table_name} ON #{klass.quoted_table_name}.id = #{Tagging.quoted_table_name}.taggable_id " + \ | |
"AND #{Tagging.quoted_table_name}.taggable_type = '#{klass.to_s}'" | |
}} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment