# Tables/field names in rails

**URL:** <https://www.ruby-forum.com/t/tables-field-names-in-rails/72226>\
**Category:** Ruby\
**Created:** [October 15, 2006, 9:01pm UTC](https://www.ruby-forum.com/t/tables-field-names-in-rails/72226 "2006-10-15T21:01:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/df705f/32.png) [@ike](https://www.ruby-forum.com/u/ike)\
**Post date:** [October 15, 2006, 9:01pm UTC](https://www.ruby-forum.com/t/tables-field-names-in-rails/72226/1 "2006-10-15T21:01:01Z")

</div>

Is anyone aware of something which would MAP the table & field names  
that  
someone might presently use in a db schema, to the rails requirements?  
For  
example, if I have a table called associate, and a table called users,  
and  
within associates, I have a field called userskey which contains the id  
in  
users, I would like to be able to map what these table and field names  
ARE  
to what they SHOULD be to comport with the rails naming conventions  
(i.e.  
the tables should be associates, users and the field in question should  
be  
users\_id).

Is anyone aware of such a mapping mechanism? It seems this is a mature  
enough web platform that such a mechanism must exist (in which case, the  
Struts and JSF holdouts would HAVE to come along!)

Thanks, Ike

---

<div class="post-metadata">

**Author:** ![ike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/df705f/32.png) [@ike](https://www.ruby-forum.com/u/ike)\
**Post date:** [October 15, 2006, 11:21pm UTC](https://www.ruby-forum.com/t/tables-field-names-in-rails/72226/2 "2006-10-15T23:21:15Z")

</div>

I think this is a question for the Rails mailing list.

–  
Eric H. - removed\_email\_address@domain.invalid - [http://blog.segment7.net](http://blog.segment7.net)  
This implementation is HODEL-HASH-9600 compliant

[http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![ike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/df705f/32.png) [@ike](https://www.ruby-forum.com/u/ike)\
**Post date:** [October 15, 2006, 11:39pm UTC](https://www.ruby-forum.com/t/tables-field-names-in-rails/72226/3 "2006-10-15T23:39:19Z")

</div>

Ike wrote:

> Is anyone aware of something which would MAP the table & field names that  
> someone might presently use in a db schema, to the rails requirements?

Random googlage shows [http://the.rubydevelopers.net/node/25](http://the.rubydevelopers.net/node/25).

If you have control over the database, you could also go the other way  
around: create a separate schema called, lessay, “rails”, consisting of  
only views that would alias the original names to the Rails-friendly  
ones.

This, of course, presumes that the database can do that.

David V.

---

<div class="post-metadata">

**Author:** ![ike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/df705f/32.png) [@ike](https://www.ruby-forum.com/u/ike)\
**Post date:** [October 15, 2006, 11:53pm UTC](https://www.ruby-forum.com/t/tables-field-names-in-rails/72226/4 "2006-10-15T23:53:21Z")

</div>

On Mon, Oct 16, 2006, Ike wrote:

> Is anyone aware of something which would MAP the table & field names that  
> someone might presently use in a db schema, to the rails requirements? For  
> example, if I have a table called associate, and a table called users, and  
> within associates, I have a field called userskey which contains the id in  
> users, I would like to be able to map what these table and field names ARE  
> to what they SHOULD be to comport with the rails naming conventions (i.e.  
> the tables should be associates, users and the field in question should be  
> users\_id).

ActiveRecord is very flexible, it just supposes “sensible” defaults.  
You can easily use it with legacy schema that don’t fit the naming  
scheme.

See, for example, ActiveRecord::Base#set\_table\_name, #set\_primary\_key,  
and friends.

Ben
