Created
July 21, 2015 09:45
-
-
Save mikecmpbll/b34311f61e6e695f1ec5 to your computer and use it in GitHub Desktop.
Yes ActiveRecord, you will bow to me.
This file contains hidden or 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
scope = RealModel.where(name: 'foo') | |
threads = [] | |
dbs.each do |db| | |
threads << Thread.new do | |
dynamic_class_name = "TempModel#{Thread.current.object_id}" | |
dynamic_class = Object.const_set(dynamic_class_name, Class.new(query_model)) | |
begin | |
con = retrieve_connection(db, resolver) | |
dynamic_class.establish_connection(con) | |
local_scope = dynamic_class.all.merge(scope) | |
results[db] = local_scope.to_a.each(&:readonly!) | |
ensure | |
dynamic_class.connection_pool.release_connection | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment