# Tutorial for mapping differently-named tables?

**URL:** <https://www.ruby-forum.com/t/tutorial-for-mapping-differently-named-tables/69118>\
**Category:** Rails\
**Created:** [September 18, 2006, 8:34pm UTC](https://www.ruby-forum.com/t/tutorial-for-mapping-differently-named-tables/69118 "2006-09-18T20:34:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hillscottc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8797f3/32.png) [@hillscottc](https://www.ruby-forum.com/u/hillscottc)\
**Post date:** [September 18, 2006, 8:34pm UTC](https://www.ruby-forum.com/t/tutorial-for-mapping-differently-named-tables/69118/1 "2006-09-18T20:34:46Z")

</div>

I am interested in testing Rails with a database whose tables are not  
named according to Ruby standards.The tables do do not use PLURAL  
names, and they use underscores.

For example, I have a table called bbc\_customer that I would like to  
use.

Any good sites which discuss how to customize in this way? thanks!

---

<div class="post-metadata">

**Author:** ![hillscottc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8797f3/32.png) [@hillscottc](https://www.ruby-forum.com/u/hillscottc)\
**Post date:** [September 18, 2006, 8:42pm UTC](https://www.ruby-forum.com/t/tutorial-for-mapping-differently-named-tables/69118/2 "2006-09-18T20:42:48Z")

</div>

There’s always the ActiveRecord documentation at [api.rubyonrails.com](http://api.rubyonrails.com).

There is a meta-function in ActiveRecord::Base named ‘set\_table\_name’  
that  
allows you to override the default table name. So in your case:

class Customer \< AR::Base  
set\_table\_name ‘bbc\_customer’  
end

However, if all of your tables start with bbc\_, then you can add a line  
to  
your config.rb:

ActiveRecord::Base.table\_name\_prefix = ‘bbc\_’  
ActiveRecord::Base.pluralize\_tables = false # May have to look this one  
up,  
I can’t remember

As for a webpage that describes all of the AR config settings, I’m not  
able  
to find one. Your best bet is to just look into the active\_record  
source,  
starting with active\_record/base.rb.

Jason

---

<div class="post-metadata">

**Author:** ![hillscottc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8797f3/32.png) [@hillscottc](https://www.ruby-forum.com/u/hillscottc)\
**Post date:** [September 18, 2006, 8:52pm UTC](https://www.ruby-forum.com/t/tutorial-for-mapping-differently-named-tables/69118/3 "2006-09-18T20:52:48Z")

</div>

That was just what I needed. Thanks for your help.

---

<div class="post-metadata">

**Author:** ![hillscottc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8797f3/32.png) [@hillscottc](https://www.ruby-forum.com/u/hillscottc)\
**Post date:** [October 18, 2006, 10:43am UTC](https://www.ruby-forum.com/t/tutorial-for-mapping-differently-named-tables/69118/4 "2006-10-18T10:43:22Z")

</div>

Ah, it’s:

ActiveRecord::Base.pluralize\_table\_names = false

It is all in base.rb, all the class-level variables.

Jason
