Welcome to mirror list, hosted at ThFree Co, Russian Federation.

subquery.rb « database « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 36e4559b554bf2b18e8e760cbb4f076fb68495f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# frozen_string_literal: true

module Gitlab
  module Database
    module Subquery
      class << self
        def self_join(relation)
          t = relation.arel_table
          t2 = if !Gitlab.rails5?
                 relation.arel.as('t2')
               else
                 # Work around a bug in Rails 5, where LIMIT causes trouble
                 # See https://gitlab.com/gitlab-org/gitlab-ce/issues/51729
                 r = relation.limit(nil).arel
                 r.take(relation.limit_value) if relation.limit_value
                 r.as('t2')
               end

          relation.unscoped.joins(t.join(t2).on(t[:id].eq(t2[:id])).join_sources.first)
        end
      end
    end
  end
end