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.
Problem i
might want to check out https://github.com/tchandy/octopus nowadays.
Another way:
class Abc < ActiveRecord::Base
establish_connection Rails.configuration.database_configuration["test"]
end
I don't know about active_delegate, but I recently had to access different databases for work applications, and nothing really fit what I wanted. So I wrote something for myself, it's running in production applications as we speak.
Fixed Link connection_ninja
I've also had to connect to, and manage, two different databases, so I created a gem called secondbase: http://github.com/karledurante/secondbase
I highly suggest MyReplication plugin for MySQL adapter which helps you switch the connection at run-time in an elegant way:
User.using(:another_database) do
u = User.all
end
https://github.com/minhnghivn/my_replication
I tried ur Sample,still getting error!!
superclass mismatch for class MysqlAdapter
I think ,the problem is with my database.yml
file .Please check this file
database_mysql:
adapter: mysql
database: project
host: localhost
username: root
password: root
port: 3306
development:
adapter: postgresql
database: codex
host: localhost
username: postgres
password: root
port: 5432
test:
adapter: postgresql
database: codex
host: localhost
username: postgres
password: root
port: 5432
production:
adapter: postgresql
database: codex
host: localhost
username: postgres
password: root
port: 5432
i start the mongrel in developemnet mode only.
here is my model superclass
$config = YAML.load_file(File.join(File.dirname(__FILE__),
'../../config/database.yml'))
class MasterDatabase < ActiveRecord::Base
self.abstract_class = true
establish_connection $config['database_mysql']
end
Please correct me..