summaryrefslogtreecommitdiffstats
path: root/app/models/query.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-01-29 20:51:48 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-01-29 20:51:48 +0000
commitcd6db6a3cbe43880eca4eec8c967fb78d95a2926 (patch)
tree42219d3f9b276f197f5045cec25639bb4e2be5fd /app/models/query.rb
parent0c5af16e14570a384e154430cd1e9fa123cdf579 (diff)
downloadredmine-cd6db6a3cbe43880eca4eec8c967fb78d95a2926.tar.gz
redmine-cd6db6a3cbe43880eca4eec8c967fb78d95a2926.zip
Adds support for multiselect custom fields (#1189).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8721 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/query.rb')
-rw-r--r--app/models/query.rb14
1 files changed, 10 insertions, 4 deletions
diff --git a/app/models/query.rb b/app/models/query.rb
index 9846acd63..1cfa952ff 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -57,7 +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)
+ if %w(list date bool int).include?(custom_field.field_format) && !custom_field.multiple?
self.groupable = custom_field.order_statement
end
self.groupable ||= false
@@ -73,8 +73,8 @@ class QueryCustomFieldColumn < QueryColumn
end
def value(issue)
- cv = issue.custom_values.detect {|v| v.custom_field_id == @cf.id}
- cv && @cf.cast_value(cv.value)
+ cv = issue.custom_values.select {|v| v.custom_field_id == @cf.id}.collect {|v| @cf.cast_value(v.value)}
+ cv.size > 1 ? cv : cv.first
end
def css_classes
@@ -694,7 +694,13 @@ class Query < ActiveRecord::Base
value.push User.current.id.to_s
end
end
- "#{Issue.table_name}.id IN (SELECT #{Issue.table_name}.id FROM #{Issue.table_name} LEFT OUTER JOIN #{db_table} ON #{db_table}.customized_type='Issue' AND #{db_table}.customized_id=#{Issue.table_name}.id AND #{db_table}.custom_field_id=#{custom_field_id} WHERE " +
+ not_in = nil
+ if operator == '!'
+ # Makes ! operator work for custom fields with multiple values
+ operator = '='
+ not_in = 'NOT'
+ end
+ "#{Issue.table_name}.id #{not_in} IN (SELECT #{Issue.table_name}.id FROM #{Issue.table_name} LEFT OUTER JOIN #{db_table} ON #{db_table}.customized_type='Issue' AND #{db_table}.customized_id=#{Issue.table_name}.id AND #{db_table}.custom_field_id=#{custom_field_id} WHERE " +
sql_for_field(field, operator, value, db_table, db_field, true) + ')'
end