简体   繁体   中英

How do I use Ruby on Rails 3.1 with DataMapper on JRuby with a DB2/400 database?

I am developing a Rails 3.1 application on top of a legacy DB2/400 database. Because of the better support for legacy schemas, I opted to use DataMapper instead of ActiveRecord as the ORM. The application is going to be deployed on JRuby .

What is the best way to access a DB2 database in this case?

My initial research indicated that this would be trivial, since one of the major selling points of using JRuby on Rails is that you get JDBC, and thus access to pretty much any database on the planet.

However, it appears that is not necessarily true, in particular, there doesn't seem to be any driver for either ActiveRecord or DataMapper/DataObjects for using DB2 over JDBC.

Do I have to write my own driver? From reading the source code of the various existing DataObjects/DataMapper JDBC drivers , this shouldn't be too hard, but it is something I'd rather like to avoid.

Is there any ready-made solution (library, gem, blog post, tutorial) for using DB2/400 with JRuby on Rails with DataMapper? If not, how do I do it?

activerecord-jdbc-adapter has built-in support for DB2. Is there a particular schema problem you have? I've been able to get ActiveRecord to work with several legacy schemas.

Update :

For table names that don't match, simply put

set_table_name "my_table_name"

in the model. You can specify the class used in a relationhip, and/or the foreign key:

has_many :somethings, :class_name => 'something_else', :foreign_key => 'something_else_id'

(For more of the options see http://apidock.com/rails/ActiveRecord/Associations/ClassMethods ).

For composite primary keys, see the Composite Primary Keys gem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM