Fixes custom field filters behaviour (#1078).

git-svn-id: http://redmine.rubyforge.org/svn/trunk@1362 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2008-04-26 16:55:24 +00:00
parent a6311a9603
commit 64474802f9
2 changed files with 4 additions and 4 deletions

View File

@ -301,7 +301,7 @@ class Query < ActiveRecord::Base
# custom field # custom field
db_table = CustomValue.table_name db_table = CustomValue.table_name
db_field = 'value' db_field = 'value'
sql << "#{Issue.table_name}.id IN (SELECT #{db_table}.customized_id FROM #{db_table} where #{db_table}.customized_type='Issue' AND #{db_table}.customized_id=#{Issue.table_name}.id AND #{db_table}.custom_field_id=#{$1} AND " sql << "#{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=#{$1} WHERE "
else else
# regular field # regular field
db_table = Issue.table_name db_table = Issue.table_name
@ -320,9 +320,9 @@ class Query < ActiveRecord::Base
when "!" when "!"
sql = sql + "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))" sql = sql + "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))"
when "!*" when "!*"
sql = sql + "#{db_table}.#{db_field} IS NULL" sql = sql + "#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} = ''"
when "*" when "*"
sql = sql + "#{db_table}.#{db_field} IS NOT NULL" sql = sql + "#{db_table}.#{db_field} IS NOT NULL AND #{db_table}.#{db_field} <> ''"
when ">=" when ">="
sql = sql + "#{db_table}.#{db_field} >= #{v.first.to_i}" sql = sql + "#{db_table}.#{db_field} >= #{v.first.to_i}"
when "<=" when "<="

View File

@ -23,7 +23,7 @@ class QueryTest < Test::Unit::TestCase
def test_query_with_multiple_custom_fields def test_query_with_multiple_custom_fields
query = Query.find(1) query = Query.find(1)
assert query.valid? assert query.valid?
assert query.statement.include?("custom_values.value IN ('MySQL')") assert query.statement.include?("#{CustomValue.table_name}.value IN ('MySQL')")
issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement issues = Issue.find :all,:include => [ :assigned_to, :status, :tracker, :project, :priority ], :conditions => query.statement
assert_equal 1, issues.length assert_equal 1, issues.length
assert_equal Issue.find(3), issues.first assert_equal Issue.find(3), issues.first