开发者

ActiveRecord > MySQL Adapter > Case Sensitivity

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 tho开发者_如何转开发ughts on how one might get around this issue?

Thanks in advance!


class Mouse < ActiveRecord::Base
  set_table_name "Meece"
end

Should clear you right up I think.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜