Skip to content

Instantly share code, notes, and snippets.

@jpawlyn
Created May 24, 2021 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpawlyn/5c09411f7da37d953c4ae639bcf41458 to your computer and use it in GitHub Desktop.
Save jpawlyn/5c09411f7da37d953c4ae639bcf41458 to your computer and use it in GitHub Desktop.
require "#{Gem.loaded_specs['activerecord'].full_gem_path}/lib/active_record/connection_adapters/abstract_adapter"
module ActiveRecord
module ConnectionAdapters
class AbstractAdapter
# we are overriding this method since connection_klass is a string when accessing a MyGem db
def preventing_writes?
return true if replica?
return ActiveRecord::Base.connection_handler.prevent_writes if ActiveRecord::Base.legacy_connection_handling
# commented out line below and replaced with an expanded guard clause
# return false if connection_klass.nil?
return false if connection_klass.nil? || connection_klass.is_a?(String)
connection_klass.current_preventing_writes
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment