Legacy naming

I have a legacy DB I’m using. To make Rails work, I’m explicitly setting
primary key names, etc. However, it strikes me that there is consistency
in the table naming, just not Rails compliant. I recall seeing ways to
tell Rails how to look for table names, column names, etc., and I was
wondering if I could save a lot of typing by setting some application
level prefs and letting Rails do the work.

To wit:

  • Table names are not pluralized, so the users’ table is named “user”.

  • Primary keys are of the form [Tablename]ID, so the users’ table has a
    primary key named “UserID”.

  • Foreign keys use the same convention, so the foreign key referencing
    users in the group table is “UserID”.

Can any of this be handled with configuration?

Brian,

Try:

set_table_name
http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000880

and

set_primary_key
http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000881

Hope that helps!

Thanks for your response, Ryan. That’s what I have been doing - what I
was hoping for was a way of setting up the environment so that I didn’t
have to do that.

I think I found some clues here:

http://fora.pragprog.com/rails-recipes/write-your-own/post/84

I’ll try it out and see.

Ryan wrote:

Brian,

Try:

set_table_name
http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000880

and

set_primary_key
http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000881

Hope that helps!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs