views:

22

answers:

1

I have a 'legacy' DB2 database that has many other applications and users. Trying to experiment with a rails app. Got everything working great with the ibm_db driver.

Problem is that I have some tables like schema1.products, schema1.sales and other tables like schema2.employees and schema2.payroll.

In the ibm_db adapter connection, I specify a schema, like schema1 or schema2, and I can work within that one schema, but I need to be able to easily (and transparently) reference both schemas basically interchangeably. I don't want to break the other apps, and the SQL I would normally write against DB2 doesn't have any of these restrictions (schemas can be mixed in SQL against DB2 without any trouble at all).

I would like to just specify table names as "schema1.products" for example and be done with it, but that doesn't seem to jive with the "rails way" of going about it.

Suggestions?

A: 

http://stackoverflow.com/questions/1226182/how-do-i-work-with-two-different-databases-in-rails-with-active-records

Will
Well, not what I was expecting, but I guess that's kind of the point. This seems to work great so far, though it seems a little overkill to have a new database connection just for a different schema. But if this is the "rails way" then I simply have to get used to it. Fortunately I only have two schemas to deal with so this should work reasonably well.Thanks so much!
GNUMatrix
If you wanted you could create views from one db to the other but that defeats the purpose of splitting them up in the first place
Will
Within DB2 itself I can also use aliases, just a bit tedious to setup especially if any table names are duplicated from one schema to another. The thing that gets me is that this is all within the same database. The schemas are basically used as formal table prefixes more than anything. My guess is that in other databases they may have a more fundamental purpose but not so much within DB2. I'm trying to stick to rails conventions as best I can as straying too far from that tends to cause lots of trouble, so this multiple database connection thing will have to do for now.
GNUMatrix
Would table_name class method in your model address this?
nessence