]> source.dussan.org Git - redmine.git/commitdiff
Adds CustomField#group_statement.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 24 Jul 2012 16:28:34 +0000 (16:28 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Tue, 24 Jul 2012 16:28:34 +0000 (16:28 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10071 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/custom_field.rb
app/models/query.rb

index 6a362cb25a2ad4381bc38f6d8db11c5db17c960d..408b54afb92471c1046a7fd0f20e94f6390bb64c 100644 (file)
@@ -128,7 +128,7 @@ class CustomField < ActiveRecord::Base
 
   # Returns a ORDER BY clause that can used to sort customized
   # objects by their value of the custom field.
-  # Returns false, if the custom field can not be used for sorting.
+  # Returns nil if the custom field can not be used for sorting.
   def order_statement
     return nil if multiple?
     case field_format
@@ -151,6 +151,18 @@ class CustomField < ActiveRecord::Base
     end
   end
 
+  # Returns a GROUP BY clause that can used to group by custom value
+  # Returns nil if the custom field can not be used for grouping.
+  def group_statement 
+    return nil if multiple?
+    case field_format
+      when 'list', 'date', 'bool', 'int'
+        order_statement
+      else
+        nil
+    end
+  end
+
   def <=>(field)
     position <=> field.position
   end
index cd3a10f0a4ae089baa136f3c62f3783ed4a199e7..b2d0189065425778fd86937820c73154d1598b9c 100644 (file)
@@ -57,10 +57,7 @@ class QueryCustomFieldColumn < QueryColumn
   def initialize(custom_field)
     self.name = "cf_#{custom_field.id}".to_sym
     self.sortable = custom_field.order_statement || false
-    if %w(list date bool int).include?(custom_field.field_format) && !custom_field.multiple?
-      self.groupable = custom_field.order_statement
-    end
-    self.groupable ||= false
+    self.groupable = custom_field.group_statement || false
     @cf = custom_field
   end