class ActiveRecord::Associations::CollectionAssociation
def target=(record)
def target=(record) return super unless reflection.klass.has_many_inversing case record when nil # It's not possible to remove the record from the inverse association. when Array super else replace_on_target(record, true, replace: true, inversing: true) end end