From fedf978f9aa1909ed7bb3fad767ad120a1c6bd7b Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 28 Jan 2020 15:08:36 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- app/models/concerns/issuable.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'app/models/concerns') 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 }) -- cgit v1.2.1