2018-09-11 19:08:34 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-20 20:03:53 +00:00
|
|
|
class UnionFinder
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2016-03-20 20:03:53 +00:00
|
|
|
def find_union(segments, klass)
|
|
|
|
if segments.length > 1
|
|
|
|
union = Gitlab::SQL::Union.new(segments.map { |s| s.select(:id) })
|
|
|
|
|
|
|
|
klass.where("#{klass.table_name}.id IN (#{union.to_sql})")
|
|
|
|
else
|
|
|
|
segments.first
|
|
|
|
end
|
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2016-03-20 20:03:53 +00:00
|
|
|
end
|