Method: Cms::Tag.counts

Defined in:
app/models/cms/tag.rb

.counts(options = {}) ⇒ Array

Returns an array of tags with a count attribute

Returns:

  • (Array)

    Each element of the area contains [Id (Integer), Name (String), count (Integer)] (with Sqlite3 anyway)



16
17
18
19
20
21
22
23
24
# File 'app/models/cms/tag.rb', line 16

def self.counts(options={})
  with_scope(:find => {
      :select => "#{Tag.table_name}.id, #{Tag.table_name}.name, count(*) as count",
      :joins => :taggings,
      :group => "#{Tag.table_name}.id, #{Tag.table_name}.name",
      :order => "count desc, #{Tag.table_name}.name"}) do
    all(options)
  end
end