Saturday, June 09, 2007

Rails with multiple databases

code In database.yml
host: # your slave’s IP
database: production
username: root
password: pass
l Define a model Slave1.rb

class Slave1 < ActiveRecord::Base
self.abstract_class = true
establish_connection :slave1

When you need to run a query on the slave, just do
Slave1.connection.execute("select * from some_table")

Magic Multi-Connections Ruby on Rails ActiveRecords

No comments :