We are getting to a point in our project where we want the different bits to start integrating. One part is Java, another is C++ and the part I am responsible for is Ruby on Rails. All of this runs off of a MySQL 5 database.
The database schema is owned by a C++ guy and while he was willing to modify some of his style to fit Rails conventions I told him not to. To be honest I was worried when I said that. It was a risk thinking that Rails would be able to handle a non-standard database. Not only were primary and join tables named completely differently to Rails conventions but the columns were quite different and the data the one Rails app needed to get at was spread over multiple databases.
About 10 minutes ago I sat back in my creaky chair and sighed a sigh of relief. It all works. Rails handles the non-standard setup just fine.
We first made views of the underlying tables (which is why we are on MySQL 5) to get as close to Rails conventions as we could. It wasn’t perfect though as all our views are prefixed. By default Rails won’t handle that unless I bastardised my model naming which we weren’t going to do. The next trick was to use AustinMoody’s def self.table_name() “mpq.mpqs” end tip to tell Rails what table (actually, views) to use. It also solved the multiple-database problem as you just prefix the table name with the database name.
I then found out about the :join_table option on has_and_belongs_to_many in your models which deals with the join tables.
And that is all it took. I am relieved and impressed with Rails. I get all the good stuff while working on a decidely non-conventional Rails database setup.
Add New Comment
Viewing 3 Comments
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Add New Comment
Trackbacks
(Trackback URL)
November 3, 2006 at 11:48 am
[...] In a previous post I showed how to use non-conventional tables in your Rails app. A few days on ...