The Life of a Radar

Connecting to Multiple Databases Using ActiveRecord
17 Oct 2009

You can call establish_connection with the key that points to another database config in your config/database.yml file

REXML could not parse this XML/HTML: 
<pre>
class Person < ActiveRecord::Base
  establish_connection(:hr)
end
</pre>
REXML could not parse this XML/HTML: 
<pre>
class Ticket < ActiveRecord::Base
  establish_connection(:bug_tracker)
end
</pre>

If you have a whole bunch of models that need to connect to another database:

REXML could not parse this XML/HTML: 
<pre>
class HR < ActiveRecord::Base
  establish_connection(:hr)
end

class People < HR
  # ...
end

class Resource < HR
  # ...
end
</pre>
blog comments powered by Disqus