##// END OF EJS Templates
Adds CustomField#group_statement....
Jean-Philippe Lang -
r9888:0b31c8ac85ba
parent child
Show More
@@ -128,7 +128,7 class CustomField < ActiveRecord::Base
128
128
129 # Returns a ORDER BY clause that can used to sort customized
129 # Returns a ORDER BY clause that can used to sort customized
130 # objects by their value of the custom field.
130 # objects by their value of the custom field.
131 # Returns false, if the custom field can not be used for sorting.
131 # Returns nil if the custom field can not be used for sorting.
132 def order_statement
132 def order_statement
133 return nil if multiple?
133 return nil if multiple?
134 case field_format
134 case field_format
@@ -151,6 +151,18 class CustomField < ActiveRecord::Base
151 end
151 end
152 end
152 end
153
153
154 # Returns a GROUP BY clause that can used to group by custom value
155 # Returns nil if the custom field can not be used for grouping.
156 def group_statement
157 return nil if multiple?
158 case field_format
159 when 'list', 'date', 'bool', 'int'
160 order_statement
161 else
162 nil
163 end
164 end
165
154 def <=>(field)
166 def <=>(field)
155 position <=> field.position
167 position <=> field.position
156 end
168 end
@@ -57,10 +57,7 class QueryCustomFieldColumn < QueryColumn
57 def initialize(custom_field)
57 def initialize(custom_field)
58 self.name = "cf_#{custom_field.id}".to_sym
58 self.name = "cf_#{custom_field.id}".to_sym
59 self.sortable = custom_field.order_statement || false
59 self.sortable = custom_field.order_statement || false
60 if %w(list date bool int).include?(custom_field.field_format) && !custom_field.multiple?
60 self.groupable = custom_field.group_statement || false
61 self.groupable = custom_field.order_statement
62 end
63 self.groupable ||= false
64 @cf = custom_field
61 @cf = custom_field
65 end
62 end
66
63
General Comments 0
You need to be logged in to leave comments. Login now