1# frozen_string_literal: true 2 3module ManualInverseAssociation 4 extend ActiveSupport::Concern 5 6 class_methods do 7 def manual_inverse_association(association, inverse) 8 define_method(association) do 9 super().tap do |value| 10 next unless value 11 12 child_association = value.association(inverse) 13 child_association.set_inverse_instance(self) 14 child_association.target = self 15 end 16 end 17 end 18 end 19end 20