Last active
June 24, 2016 09:53
-
-
Save mfazekas/cc7792802859d91e3fcb to your computer and use it in GitHub Desktop.
Monkey patch for fixing infinite loop in autosave_association
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# fixes 'https://github.com/rails/rails/pull/16640' | |
# add this to lib/patches/active_record/autosave_association.rb | |
# then in config/environment.rb before initialize! load this file with | |
# something like: | |
# require File.join(File.dirname(__FILE__), '../lib/patches/active_record/autosave_association.rb') | |
# see https://gist.github.com/mfazekas/cc7792802859d91e3fcb | |
require 'active_record/autosave_association' | |
module ActiveRecord | |
module AutosaveAssociationInfLoopPatch | |
def nested_records_changed_for_autosave? | |
@_nested_records_changed_for_autosave_already_called ||= false | |
return false if @_nested_records_changed_for_autosave_already_called | |
begin | |
@_nested_records_changed_for_autosave_already_called = true | |
super | |
ensure | |
@_nested_records_changed_for_autosave_already_called = false | |
end | |
end | |
end | |
class Base | |
prepend AutosaveAssociationInfLoopPatch | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment