]> source.dussan.org Git - redmine.git/commitdiff
Multiple issue ids in "Related to" filter (#38301).
authorGo MAEDA <maeda@farend.jp>
Sat, 25 Mar 2023 06:27:30 +0000 (06:27 +0000)
committerGo MAEDA <maeda@farend.jp>
Sat, 25 Mar 2023 06:27:30 +0000 (06:27 +0000)
Patch by Tomoko Shimizu, Ko Nagase, and Takashi Kato.

git-svn-id: https://svn.redmine.org/redmine/trunk@22156 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index eb7684cc2b282305e666b2ed6e40114e4d78c989..9f541cc5463742f009684678510d026d251e49a1 100644 (file)
@@ -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" ? '<>' : '=')
index c2cbf6feefa110b592a597f1fb2aefbce44793cb..b41aa507c4ab55e3488b24678d14f988a418770b 100644 (file)
@@ -1337,9 +1337,17 @@ class QueryTest < ActiveSupport::TestCase
     query.filters = {"relates" => {:operator => '=', :values => ['2']}}
     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