Vote #80524
完了Issue relations filter lacks "is not"
0%
説明
It seems the "is not" operator was omitted in the :relation definition of query operators.
The actual implementation seems to have it, though.
The attached patch adds the operator to the list (applied to Redmine 4.0.5).
journals
Alexander Achenbach wrote:
> The actual implementation seems to have it, though.
The implementation for "is not" operator is at source:tags/4.0.5/app/models/issue_query.rb#L568. I think "!" operator was not included by mistake and this should be fixed.
<pre><code class="ruby">
when "=", "!"
op = (operator == "=" ? 'IN' : 'NOT IN')
"#{Issue.table_name}.id #{op} (SELECT DISTINCT #{IssueRelation.table_name}.#{join_column} 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})"
</code></pre>
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Go MAEDA wrote:
> The implementation for "is not" operator is at source:tags/4.0.5/app/models/issue_query.rb#L568. I think "!" operator was not included by mistake and this should be fixed.
I started to wonder whether the "is not" filter is practical.
The reason is that the "is not" filter returns too many results. In many cases, it returns almost all issues in the project.
Suppose that there are 1000 issues in the project, and issue 2 and issue 3 have a "related to" relationship with each other. if you apply the filter "Related to" "is not" "3", it returns 999 issues other than issue 2.
I think the result is not so useful.
--------------------------------------------------------------------------------
Go MAEDA wrote:
> I started to wonder whether the "is not" filter is practical.
>
> The reason is that the "is not" filter returns too many results. In many cases, it returns almost all issues in the project.
Sorry, I have changed my mind. Please forget what I wrote in #32546#note-4.
Although I wrote "is not" filter is not so useful, it is wrong. It is useful when it is used with the combination with other filters. For example:
* "Subject" "contains" "awesome feature"
* "Is duplicate of" "is not" "10"
Suppose that issue 10 is an issue to implement an awesome feature. There are lot of duplicate issues and you want to create "Is duplicte of" relation ship for all those issues. You can find issues without "Is duplicate of" relationship by the above filter.
--------------------------------------------------------------------------------
Here is a test for the patch.
<pre><code class="diff">
diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb
index df6c61551..56ec82d14 100644
--- a/test/unit/query_test.rb
+++ b/test/unit/query_test.rb
@@ -1153,6 +1153,10 @@ class QueryTest < ActiveSupport::TestCase
query = IssueQuery.new(:name => '_')
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']}}
+ assert_equal Issue.where.not(:id => [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
</code></pre>
--------------------------------------------------------------------------------
Go MAEDA wrote:
> It is useful when it is used with the combination with other filters. [...]
Admittedly we have not had a need for this in years of using Redmine, but projects have become somewhat more complex, and now our use case is a pending re-factorization of related issues, so we have to look for issues "related to A, but not related to B" prior to updating their relations.
Thanks for the test.
--------------------------------------------------------------------------------
Setting the target version to 4.2.0.
--------------------------------------------------------------------------------
Committed the patch. Thank you for reporting and fixing the issue.
--------------------------------------------------------------------------------
I propose to merge this small fix into 4.1-stable.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
related_issues
relates,Closed,3265,Filter on issue relations