开发者

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

开发者 https://www.devze.com 2023-03-28 22:57 出处:网络
Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 3 ye开发者_如何转开发ars ago.

Improve this question

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号