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

manual_inverse_association.rb « concerns « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d0d781dc15f84a312bf3e5c4e96dd2e9aa9baa1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# frozen_string_literal: true

module ManualInverseAssociation
  extend ActiveSupport::Concern

  module ClassMethods
    def manual_inverse_association(association, inverse)
      define_method(association) do |*args|
        super(*args).tap do |value|
          next unless value

          child_association = value.association(inverse)
          child_association.set_inverse_instance(self)
          child_association.target = self
        end
      end
    end
  end
end