@@ -577,8 +577,11 class Query < ActiveRecord::Base | |||
|
577 | 577 | customized_class = queried_class.reflect_on_association(assoc.to_sym).klass.base_class rescue nil |
|
578 | 578 | raise "Unknown #{queried_class.name} association #{assoc}" unless customized_class |
|
579 | 579 | end |
|
580 | "#{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 " + | |
|
581 | sql_for_field(field, operator, value, db_table, db_field, true) + ')' | |
|
580 | where = sql_for_field(field, operator, value, db_table, db_field, true) | |
|
581 | if operator =~ /[<>]/ | |
|
582 | where = "(#{where}) AND #{db_table}.#{db_field} <> ''" | |
|
583 | end | |
|
584 | "#{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})" | |
|
582 | 585 | end |
|
583 | 586 | |
|
584 | 587 | # Helper method to generate the WHERE sql for a +field+, +operator+ and a +value+ |
@@ -364,6 +364,20 class QueryTest < ActiveSupport::TestCase | |||
|
364 | 364 | find_issues_with_query(query) |
|
365 | 365 | end |
|
366 | 366 | |
|
367 | def test_operator_lesser_than_on_date_custom_field | |
|
368 | f = IssueCustomField.create!(:name => 'filter', :field_format => 'date', :is_filter => true, :is_for_all => true) | |
|
369 | CustomValue.create!(:custom_field => f, :customized => Issue.find(1), :value => '2013-04-11') | |
|
370 | CustomValue.create!(:custom_field => f, :customized => Issue.find(2), :value => '2013-05-14') | |
|
371 | CustomValue.create!(:custom_field => f, :customized => Issue.find(3), :value => '') | |
|
372 | ||
|
373 | query = IssueQuery.new(:project => Project.find(1), :name => '_') | |
|
374 | query.add_filter("cf_#{f.id}", '<=', ['2013-05-01']) | |
|
375 | issue_ids = find_issues_with_query(query).map(&:id) | |
|
376 | assert_include 1, issue_ids | |
|
377 | assert_not_include 2, issue_ids | |
|
378 | assert_not_include 3, issue_ids | |
|
379 | end | |
|
380 | ||
|
367 | 381 | def test_operator_between |
|
368 | 382 | query = IssueQuery.new(:project => Project.find(1), :name => '_') |
|
369 | 383 | query.add_filter('done_ratio', '><', ['30', '40']) |
General Comments 0
You need to be logged in to leave comments.
Login now