RoR 3.1 Mysql2 适配器 +当表名以字母“y”结尾时,远程数据库不工作
我不确定这是一个错误还是我完全疯了。
我有一个远程数据库,我可以对除以字母“y”结尾的表之外的所有表进行查询
我的模型:ox_stats_country.rb
class OxStatsCountry < ActiveRecord::Base
establish_connection :openx
self.abstract_class = true
end
远程/旧数据库上的表名称是“ox_stats_country”。
当我尝试在 Rails 控制台中查询如下内容时:“OxStatsCountry.find(1)”时,
出现以下错误:
ActiveRecord::StatementInvalid: Mysql2::Error: 表“openx.ox_stats_countries”不存在:显示来自
ox_stats_countries
的字段
如您所见,它会自动将表名称复数化,因此无法找到它。我对表名“agency”也有同样的问题。然而,对于所有其他表(不以字母“y”结尾),一切正常。
这是 mysql2 适配器的错误吗?如果是这样,我应该在哪里提交这样的错误?您对如何解决这个问题有什么想法吗?我对 RoR 和一般编程都很陌生,所以我将不胜感激任何形式的帮助。
感谢您抽出时间...乌利
I am not sure whether this is a bug or if I have totally gone mad.
I have a remote database and I am able to make queries on all tables except tables which end with the letter "y"
My model: ox_stats_country.rb
class OxStatsCountry < ActiveRecord::Base
establish_connection :openx
self.abstract_class = true
end
The table name on the remote/legacy database is "ox_stats_country".
When I try to query something in the rails console like this: "OxStatsCountry.find(1)"
I get the following error:
ActiveRecord::StatementInvalid: Mysql2::Error: Table 'openx.ox_stats_countries' doesn't exist: SHOW FIELDS FROM
ox_stats_countries
As you can see, it pluralizes automatically the table name and hence is not able to find it. I have the same problem with the table name "agency". Yet with all the other tables (not ending with the letter "y") everything works fine.
Is this a bug of the mysql2 adapter? If so, where would I file such bug? Do you have any ideas on how to solve this? I am newbish to RoR and programming in general so I would appreciate any kind of help.
Thanks for your time... Uli
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,ActiveRecord 默认情况下会查找复数表名。您的表名称应该是复数(例如,机构)。但是,您可以在模型中使用以下内容覆盖表名称:
Well, ActiveRecord looks for plural table names by default. Your table names should be plural (agencies, for example). However, you can override the table name with this in your model:
不确定错误问题,但我知道您可以使用
set_table_name "ox_stats_country"
从 api 手动设置模型的表名称:http://api.rubyonrails.org/classes/ActiveRecord/Base.html#method-c-set_table_name
Not sure about the bug question, but I know you can manually set the table name of a model with
set_table_name "ox_stats_country"
From the api: http://api.rubyonrails.org/classes/ActiveRecord/Base.html#method-c-set_table_name