Tutorial for mapping differently-named tables?

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

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

There’s always the ActiveRecord documentation at api.rubyonrails.com.

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

class Customer < AR::Base
set_table_name ‘bbc_customer’

However, if all of your tables start with bbc_, then you can add a line
your config.rb:

ActiveRecord::Base.table_name_prefix = ‘bbc_’
ActiveRecord::Base.pluralize_tables = false # May have to look this one
I can’t remember

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


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

Ah, it’s:

ActiveRecord::Base.pluralize_table_names = false

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


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