diff options
Diffstat (limited to 'app/models/concerns/issuable.rb')
-rw-r--r-- | app/models/concerns/issuable.rb | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index fe0fad4b9d5..653dc9c0b47 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -108,7 +108,9 @@ module Issuable where("NOT EXISTS (SELECT TRUE FROM #{to_ability_name}_assignees WHERE #{to_ability_name}_id = #{to_ability_name}s.id)") end scope :assigned_to, ->(u) do - where("EXISTS (SELECT TRUE FROM #{to_ability_name}_assignees WHERE user_id = ? AND #{to_ability_name}_id = #{to_ability_name}s.id)", u.id) + assignees_table = Arel::Table.new("#{to_ability_name}_assignees") + sql = assignees_table.project('true').where(assignees_table[:user_id].in(u)).where(Arel::Nodes::SqlLiteral.new("#{to_ability_name}_id = #{to_ability_name}s.id")) + where("EXISTS (#{sql.to_sql})") end # rubocop:enable GitlabSecurity/SqlInjection @@ -263,8 +265,9 @@ module Issuable .reorder(Gitlab::Database.nulls_last_order('highest_priority', direction)) end - def with_label(title, sort = nil) - if title.is_a?(Array) && title.size > 1 + def with_label(title, sort = nil, not_query: false) + multiple_labels = title.is_a?(Array) && title.size > 1 + if multiple_labels && !not_query joins(:labels).where(labels: { title: title }).group(*grouping_columns(sort)).having("COUNT(DISTINCT labels.title) = #{title.size}") else joins(:labels).where(labels: { title: title }) |