summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/query.rb6
-rw-r--r--test/unit/query_test.rb2
2 files changed, 4 insertions, 4 deletions
diff --git a/app/models/query.rb b/app/models/query.rb
index c54c143e2..641c0d17b 100644
--- a/app/models/query.rb
+++ b/app/models/query.rb
@@ -301,7 +301,7 @@ class Query < ActiveRecord::Base
# custom field
db_table = CustomValue.table_name
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
# regular field
db_table = Issue.table_name
@@ -320,9 +320,9 @@ class Query < ActiveRecord::Base
when "!"
sql = sql + "(#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} NOT IN (" + v.collect{|val| "'#{connection.quote_string(val)}'"}.join(",") + "))"
when "!*"
- sql = sql + "#{db_table}.#{db_field} IS NULL"
+ sql = sql + "#{db_table}.#{db_field} IS NULL OR #{db_table}.#{db_field} = ''"
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 ">="
sql = sql + "#{db_table}.#{db_field} >= #{v.first.to_i}"
when "<="
diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb
index 3a9d19112..d291018fb 100644
--- a/test/unit/query_test.rb
+++ b/test/unit/query_test.rb
@@ -23,7 +23,7 @@ class QueryTest < Test::Unit::TestCase
def test_query_with_multiple_custom_fields
query = Query.find(1)
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
assert_equal 1, issues.length
assert_equal Issue.find(3), issues.first