# File lib/multi_db/active_record_extensions.rb, line 47 def connection self.connection_proxy end
make caching always use the ConnectionProxy
# File lib/multi_db/active_record_extensions.rb, line 30 def cache(&block) if ActiveRecord::Base.configurations.blank? yield else self.connection_proxy.cache(&block) end end
# File lib/multi_db/active_record_extensions.rb, line 43 def hijack_connection return if ConnectionProxy.master_models.include?(self.to_s) logger.info "[MULTIDB] hijacking connection for #{self.to_s}" class << self def connection self.connection_proxy end end end
# File lib/multi_db/active_record_extensions.rb, line 38 def inherited(child) super child.hijack_connection end
Make sure transactions always switch to the master
# File lib/multi_db/active_record_extensions.rb, line 21 def transaction(options = {}, &block) if self.connection.kind_of?(ConnectionProxy) super else self.connection_proxy.with_master { super } end end