]> source.dussan.org Git - redmine.git/commitdiff
Merge r21833 to 4.2-stable (#37268).
authorMarius Balteanu <marius.balteanu@zitec.com>
Mon, 26 Sep 2022 21:44:36 +0000 (21:44 +0000)
committerMarius Balteanu <marius.balteanu@zitec.com>
Mon, 26 Sep 2022 21:44:36 +0000 (21:44 +0000)
git-svn-id: https://svn.redmine.org/redmine/branches/4.2-stable@21848 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/query.rb

index 03754ccfdef3b9ac9c4ad5852385d46500951e0f..fc8a44a774cb13ee1d64a87309ab1728ef3047fc 100644 (file)
@@ -1151,12 +1151,13 @@ class Query < ActiveRecord::Base
     if /[<>]/.match?(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}" \
+    "#{not_in} EXISTS (" \
+      "SELECT ct.id FROM #{customized_class.table_name} ct" \
       " 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}.customized_id=ct.id" \
       " AND #{db_table}.custom_field_id=#{custom_field_id}" \
-      " WHERE (#{where}) AND (#{filter[:field].visibility_by_project_condition}))"
+      " WHERE #{queried_table_name}.#{customized_key} = ct.id AND " \
+      "  (#{where}) AND (#{filter[:field].visibility_by_project_condition}))"
   end
 
   def sql_for_chained_custom_field(field, operator, value, custom_field_id, chained_custom_field_id)