establish_connection
- ActiveRecord::ConnectionHandling
- self.establish_connection
- ここにDB名を書くと、そのテーブルだけそのDBを見に行く(らしい
class User < ApplicationRecord establish_connection :hogera end > User.all #=> Traceback (most recent call last): 3: from (irb):1 2: from app/models/user.rb:1:in `<main>' 1: from app/models/user.rb:2:in `<class:User>' ActiveRecord::AdapterNotSpecified ('hogera' database is not configured. Available: ["default", "development", "test", "production"])
- https://github.com/rails/rails/blob/master/activerecord/lib/active_record/core.rb
[57, 66] in /usr/local/var/rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.1/lib/active_record/connection_handling.rb
57: spec = resolver.resolve(config).symbolize_keys
58: spec[:name] = spec_name
59:
60: byebug
61:
=> 62: connection_handler.establish_connection(spec)
63: end
64:
65: class MergeAndResolveDefaultUrlConfig # :nodoc:
66: def initialize(raw_configurations)
[55, 64] in /usr/local/var/rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.1/lib/active_record/core.rb
55: end
56: self.configurations = {}
57:
58: # Returns fully resolved configurations hash
59: def self.configurations
=> 60: @@configurations
61: end
62:
63: ##
64: # :singleton-method:
(byebug) @@configurations
{"default"=>{"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000}, "development"=>{"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000, "database"=>"db/development.sqlite3"}, "test"=>{"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000, "database"=>"db/test.sqlite3"}, "production"=>{"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000, "database"=>"db/production.sqlite3"}}
[128, 137] in /usr/local/var/rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.1/lib/active_record/connection_handling.rb
128: def remove_connection(name = nil)
129: name ||= @connection_specification_name if defined?(@connection_specification_name)
130: # if removing a connection that has a pool, we reset the
131: # connection_specification_name so it will use the parent
132: # pool.
=> 133: if connection_handler.retrieve_connection_pool(name)
134: self.connection_specification_name = nil
135: end
136:
137: connection_handler.remove_connection(name)
(byebug) @connection_specification_name
"primary"