Skip to content

Instantly share code, notes, and snippets.

@armstrjare
Created October 15, 2011 06:15
Show Gist options
  • Save armstrjare/1289136 to your computer and use it in GitHub Desktop.
Save armstrjare/1289136 to your computer and use it in GitHub Desktop.
Temporary monkeypatch to fix a bug with ActiveRecord::AutosaveAssociation until it's fixed upstream.
module ActiveRecord
module AutosaveAssociationFix
private
def associated_records_to_validate_or_save(*)
# There exists a case (new_record) where the returned array is actually the internal collection array.
# Unfortunately, this now gets mutated when records are removed. This means use of mark_for_destruction
# (to prevent creation of built records) can result in some records not being iterated over (and
# consequently not saved) on creation.
super.try(:dup)
end
end
ActiveSupport::Deprecation.warn("Including Rails 3.1 AutosaveAssociation fix monkey patch. This should be removed when fixed in Rails.")
ActiveRecord::Base.send(:include, AutosaveAssociationFix)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment