debian-mirror-gitlab/app/models/concerns/manual_inverse_association.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

20 lines
462 B
Ruby
Raw Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module ManualInverseAssociation
extend ActiveSupport::Concern
2018-11-20 20:47:30 +05:30
class_methods do
2018-03-17 18:26:18 +05:30
def manual_inverse_association(association, inverse)
2019-03-02 22:35:43 +05:30
define_method(association) do
super().tap do |value|
2018-03-17 18:26:18 +05:30
next unless value
child_association = value.association(inverse)
child_association.set_inverse_instance(self)
child_association.target = self
end
end
end
end
end