Snipped some stuff for brevity...
Linda Metcalfe wrote:
How can I get RoR to see the third schema has been added? Any help
would be appreciated!
From my database.yml...It's not recognizing development_db2 is there.
development_db1:
adapter: mysql
database: db1_development
username: root
password:
host: localhost
development_db2:
adapter: mysql
database: db2_development
username: root
password:
host: localhost
(First although its' not WRONG what you have here, switch the naming
convention to 'name'_'environment'. That just seems to be the norm.)
Ex:
db2_development:
adapter: mysql
etc etc etc.
Make sure you have a model class extending ActiveRecord::Base and have
this class establish a connection (Using the attributes defined in your
.yml config file automatically). Like so...
class Db1Base < ActiveRecord::Base
# Prevents Single Table Inheritance from being 'assumed'
self.abstract_class = true
# Ties all extending models to this definition section in the
database.yml
establish_connection "db1_#{RAILS_ENV}"
end
class Db2Base < ActiveRecord::Base
# Prevents Single Table Inheritance from being 'assumed'
self.abstract_class = true
# Ties all extending models to this definition section in the
database.yml
establish_connection "db2_#{RAILS_ENV}"
end
Now have all classes needing this DB extend the new Db1/2Base classes
Class SomeClassUsingTheDb1Definition < Db1Base
# This would connect to the DB1 database.
end
Class SomeClassUsingTheDb2Definition < Db2Base
# This would connect to the DB2 database.
end
You could put the establish_connection in each Model class directly, but
using a base class to extend from keeps the created connections to a
minimum in your connection pool.
Hope this helps.
P.S. Thanks to Obie Fernandez (The Rails Way), Rails Docs and PragDave
for the info. (I had to read those sources a couple of times myself
before I 'got it' the first time.