]> source.dussan.org Git - redmine.git/commitdiff
Merged r11850 from trunk (#14051).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 18 May 2013 19:35:26 +0000 (19:35 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 18 May 2013 19:35:26 +0000 (19:35 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/2.3-stable@11872 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/query.rb
test/unit/query_test.rb

index db6ca07a50a60f4c3fdab1d6c6d7724506271ba5..a5e7abd4c33d613b4ac8503989ae81d9402e1dbd 100644 (file)
@@ -577,8 +577,11 @@ class Query < ActiveRecord::Base
       customized_class = queried_class.reflect_on_association(assoc.to_sym).klass.base_class rescue nil
       raise "Unknown #{queried_class.name} association #{assoc}" unless customized_class
     end
-    "#{queried_table_name}.#{customized_key} #{not_in} IN (SELECT #{customized_class.table_name}.id FROM #{customized_class.table_name} LEFT OUTER JOIN #{db_table} ON #{db_table}.customized_type='#{customized_class}' AND #{db_table}.customized_id=#{customized_class.table_name}.id AND #{db_table}.custom_field_id=#{custom_field_id} WHERE " +
-      sql_for_field(field, operator, value, db_table, db_field, true) + ')'
+    where = sql_for_field(field, operator, value, db_table, db_field, true)
+    if operator =~ /[<>]/
+      where = "(#{where}) AND #{db_table}.#{db_field} <> ''"
+    end
+    "#{queried_table_name}.#{customized_key} #{not_in} IN (SELECT #{customized_class.table_name}.id FROM #{customized_class.table_name} LEFT OUTER JOIN #{db_table} ON #{db_table}.customized_type='#{customized_class}' AND #{db_table}.customized_id=#{customized_class.table_name}.id AND #{db_table}.custom_field_id=#{custom_field_id} WHERE #{where})"
   end
 
   # Helper method to generate the WHERE sql for a +field+, +operator+ and a +value+
index bf194155ea106e315965c9153568e5090dd67058..f19a75924e915e3d96c24c8c524c7099140e7c95 100644 (file)
@@ -337,6 +337,20 @@ class QueryTest < ActiveSupport::TestCase
     find_issues_with_query(query)
   end
 
+  def test_operator_lesser_than_on_date_custom_field
+    f = IssueCustomField.create!(:name => 'filter', :field_format => 'date', :is_filter => true, :is_for_all => true)
+    CustomValue.create!(:custom_field => f, :customized => Issue.find(1), :value => '2013-04-11')
+    CustomValue.create!(:custom_field => f, :customized => Issue.find(2), :value => '2013-05-14')
+    CustomValue.create!(:custom_field => f, :customized => Issue.find(3), :value => '')
+
+    query = IssueQuery.new(:project => Project.find(1), :name => '_')
+    query.add_filter("cf_#{f.id}", '<=', ['2013-05-01'])
+    issue_ids = find_issues_with_query(query).map(&:id)
+    assert_include 1, issue_ids
+    assert_not_include 2, issue_ids
+    assert_not_include 3, issue_ids
+  end
+
   def test_operator_between
     query = IssueQuery.new(:project => Project.find(1), :name => '_')
     query.add_filter('done_ratio', '><', ['30', '40'])