title: Multiple database connection in Rails
body: <p>I'm using active_delegate for multiple connection in Rails. Here I'm using mysql as master_database for some models,and postgresql for some other models.</p>
  
  <p>Problem is that when I try to access the mysql models, I'm getting the error below! Stack trace shows that, it is still using the postgresql adapter to access my mysql models!</p>
  
  <pre><code>RuntimeError: ERROR C42P01  Mrelation "categories" does not exist   P15 F.\src\backend\parser\parse_relation.c  L886    RparserOpenTable: SELECT * FROM "categories" 
  
  STACKTRACE
  ===========
  d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract_adapter.rb:212:in `log'
  d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/postgresql_adapter.rb:507:in `execute'
  d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/postgresql_adapter.rb:985:in `select_raw'
  d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/postgresql_adapter.rb:972:in `select'
  d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache'
  d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/query_cache.rb:60:in `select_all'
  d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/query_cache.rb:81:in `cache_sql'
  d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract/query_cache.rb:60:in `select_all'
  d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:661:in `find_by_sql'
  d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1553:in `find_every'
  d:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:615:in `find'
  D:/ROR/Aptana/dedomenon/app/models/category.rb:50:in `get_all_with_exclusive_scope'
  D:/ROR/Aptana/dedomenon/app/models/category.rb:50:in `get_all_with_exclusive_scope'
  D:/ROR/Aptana/dedomenon/app/controllers/categories_controller.rb:48:in `index'
  </code></pre>
  
  <p>here is my <code>database.yml</code> file </p>
  
  <pre><code>postgre: &amp;postgre
    adapter: postgresql
    database: codex
    host: localhost
    username: postgres
    password: root
    port: 5432  
  
  mysql: &amp;mysql
    adapter: mysql
    database: project
    host: localhost
    username: root
    password: root
    port: 3306  
  
  development:
    &lt;&lt;: *postgre
  
  test:
    &lt;&lt;: *postgre
  
  production:
    &lt;&lt;: *postgre
  
  master_database:
    &lt;&lt;: *mysql
  </code></pre>
  
  <p>and my <code>master_database</code> model is like this</p>
  
  <pre><code>class Category &lt; ActiveRecord::Base
  
    delegates_connection_to :master_database, :on =&gt; [:create, :save, :destroy]
  
  end
  </code></pre>
  
  <p>Anyone has any solution??</p>