Skip to content

Commit

Permalink
Fix default connection.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Staubo committed May 18, 2011
1 parent 5b24a72 commit 4ac4e2a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/multidb/balancer.rb
Expand Up @@ -20,6 +20,7 @@ def connection
class Balancer

def initialize(configuration)
@default_candidate = Candidate.new(@configuration.default_adapter)
@candidates = {}.with_indifferent_access
@configuration = configuration
@configuration.raw_configuration[:databases].each_pair do |name, config|
Expand All @@ -31,7 +32,7 @@ def initialize(configuration)
end
end
unless @candidates.include?(:default)
@candidates[:default] = [Candidate.new(@configuration.default_adapter)]
@candidates[:default] = [@default_candidate]
end
end

Expand Down Expand Up @@ -64,7 +65,7 @@ def use(name, &block)
end

def current_connection
Thread.current[:multidb_connection] ||= ActiveRecord::Base.connection_pool.connection
Thread.current[:multidb_connection] ||= @default_candidate.connection
end

class << self
Expand Down

0 comments on commit 4ac4e2a

Please sign in to comment.