Skip to content

Instantly share code, notes, and snippets.

@zdennis
Created September 24, 2020 21:18
Show Gist options
  • Save zdennis/6449361fb7ff243f0a2080966dfbdd5e to your computer and use it in GitHub Desktop.
Save zdennis/6449361fb7ff243f0a2080966dfbdd5e to your computer and use it in GitHub Desktop.
DisableSettingInverse.disabled = true
child = Child.new(parent_id: 12345)
parent = Parent.new
parent.children = [child]
child.parent_id # => 12345
DisableSettingInverse.disabled = false
module DisableSettingInverse
class << self
attr_accessor :disabled
end
def set_inverse_instance(record)
super unless DisableSettingInverse.disabled
end
end
ActiveRecord::Associations::CollectionAssociation.prepend DisableSettingInverse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment