genki-dm-is-taggable 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
@@ -22,11 +22,13 @@ module DataMapper
|
|
22
22
|
|
23
23
|
module TaggingClassMethods
|
24
24
|
def total(options = {})
|
25
|
-
property = DataMapper::Property.new(Tagging, :"count(*)",
|
25
|
+
property = DataMapper::Property.new(Tagging, :"count(*)",
|
26
|
+
Integer, :auto_validation => false)
|
26
27
|
order = options[:order] || :desc
|
27
28
|
dir = DataMapper::Query::Direction.new(property, order)
|
28
29
|
tag_id_to_count = Tagging.aggregate(:all.count,
|
29
30
|
options.merge(:fields => [:tag_id], :order => [dir]))
|
31
|
+
return [] if tag_id_to_count.empty?
|
30
32
|
tag_ids, counts = tag_id_to_count.transpose
|
31
33
|
Tag.all(:id => tag_ids).zip counts
|
32
34
|
end
|