summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2023-03-25 06:27:30 +0000
committerGo MAEDA <maeda@farend.jp>2023-03-25 06:27:30 +0000
commit0fb007cc029cca7ddb97a00e76180052b1ed0230 (patch)
tree28ef482d75d1b33c0bfa7d23f8b5c72aafccf827
parent53f2aca3ef4976a48392367e5892caf71ac28046 (diff)
downloadredmine-0fb007cc029cca7ddb97a00e76180052b1ed0230.tar.gz
redmine-0fb007cc029cca7ddb97a00e76180052b1ed0230.zip
Multiple issue ids in "Related to" filter (#38301).
Patch by Tomoko Shimizu, Ko Nagase, and Takashi Kato. git-svn-id: https://svn.redmine.org/redmine/trunk@22156 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/models/issue_query.rb3
-rw-r--r--test/unit/query_test.rb8
2 files changed, 10 insertions, 1 deletions
diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb
index eb7684cc2..9f541cc54 100644
--- a/app/models/issue_query.rb
+++ b/app/models/issue_query.rb
@@ -723,6 +723,7 @@ class IssueQuery < Query
relation_type = relation_options[:reverse] || relation_type
join_column, target_join_column = target_join_column, join_column
end
+ ids = value.first.to_s.scan(/\d+/).map(&:to_i).uniq
sql =
case operator
when "*", "!*"
@@ -739,7 +740,7 @@ class IssueQuery < Query
" FROM #{IssueRelation.table_name}" \
" WHERE #{IssueRelation.table_name}.relation_type =" \
" '#{self.class.connection.quote_string(relation_type)}'" \
- " AND #{IssueRelation.table_name}.#{target_join_column} = #{value.first.to_i})"
+ " AND #{IssueRelation.table_name}.#{target_join_column} IN (#{ids.join(",")}))"
when "=p", "=!p", "!p"
op = (operator == "!p" ? 'NOT IN' : 'IN')
comp = (operator == "=!p" ? '<>' : '=')
diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb
index c2cbf6fee..b41aa507c 100644
--- a/test/unit/query_test.rb
+++ b/test/unit/query_test.rb
@@ -1338,8 +1338,16 @@ class QueryTest < ActiveSupport::TestCase
assert_equal [1], find_issues_with_query(query).map(&:id).sort
query = IssueQuery.new(:name => '_')
+ query.filters = {"relates" => {:operator => '=', :values => ['1,2']}}
+ assert_equal [1, 2, 3], find_issues_with_query(query).map(&:id).sort
+
+ query = IssueQuery.new(:name => '_')
query.filters = {"relates" => {:operator => '!', :values => ['1']}}
assert_equal Issue.where.not(:id => [2, 3]).order(:id).ids, find_issues_with_query(query).map(&:id).sort
+
+ query = IssueQuery.new(:name => '_')
+ query.filters = {"relates" => {:operator => '!', :values => ['1,2']}}
+ assert_equal Issue.where.not(:id => [1, 2, 3]).order(:id).ids, find_issues_with_query(query).map(&:id).sort
end
def test_filter_on_relations_with_any_issues_in_a_project