debian-mirror-gitlab/app/models/concerns/manual_inverse_association.rb
2018-03-17 18:26:18 +05:30

17 lines
447 B
Ruby

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