views:

28

answers:

2

I am working with a MySQL database that has capitalized table/field names like Users, Institutions, etc. Because the operating system of the database host is Linux, identifiers (like the table names) are treated as case sensitive. So, failing to capitalize a table name will result in a table does not exist error.

The problem I am trying to solve is that ActiveRecord always constructs identifiers in lower case. So, for example, if use the "find" method to grab the first record from the Institution table, the resulting SQL will look like:

SELECT `institutions`.* FROM `institutions` LIMIT 1

This, of course, results in a MySQL error in a Linux environment because it is not case sensitive.

Any thoughts on how one might get around this issue?

Thanks in advance!

+2  A: 
class Mouse < ActiveRecord::Base
  set_table_name "Meece"
end

Should clear you right up I think.

Chuck Vose
+1  A: 

Rails use convention over configuration to determine the name of the table from a model.

But you can always tweak the default to match your legacy databases. Have a look here:

http://book.opensourceproject.org.cn/lamp/ruby/railscook/opensource/0596527314/i_0596527314_chp_3_sect_20.html

and here:

http://railsapi.com/doc/rails-v3.0.0/classes/ActiveRecord/Base.html#M001129

hellvinz
Thanks for providing these links! That is exactly what I was looking for.
Andrew Kirk