In my current project we’re using three databases and using joins
inbetween them and when working on testing, it just did not seem to
work to have multiple databases and using the set_table_name function
since it hardcodes it to one database.
From just looking around at some code, I copied and pasted this
together, which I will use to extend my models from (There are three
I could still use the one core database through the database.yml and
only extend 2 of them.
Here is what I have. Example of one of the three.
In environment.rb I have
PRODUCTS_DATABASE = “products”
def self.included(base) #:nodoc:
base_table_name = PRODUCTS_DATABASE + “.” + value
if RAILS_ENV == “production”
set_table_name(base_table_name + “_” + RAILS_ENV)
class ProductsDatabase < ActiveRecord::Base
class Testing < ProductsDatabase
belongs_to :create_user, :foreign_key => “created_by”, :class_name
belongs_to :update_user, :foreign_key => “updated_by”, :class_name
This will produce products.testings["","_test","_development] for the
I was just wondering if there is a better solution out there, perhaps
something within rails to do what I need it to do.