【发布时间】:2011-11-15 22:17:26
【问题描述】:
我有一个现有的数据库,其中包含一些使用列名attribute 的表。我根本无法更改此名称,因为这意味着重新编译我们的整个应用程序。
当尝试访问数据库时,我最终得到:
attribute? is defined by ActiveRecord
首先我尝试使用 datamapper,但我无法继续使用它,我发现自己正在修复不应该被破坏的东西 - 比如嵌套属性....
所以,我回到了 ar 并使用它来解决问题:
class Radcheck < ActiveRecord::Base
set_table_name 'radcheck'
class << self
def instance_method_already_implemented?(method_name)
return true if method_name == 'attribute?'
return true if method_name == 'attribute_before_type_cast'
return true if method_name == 'attribute='
return true if method_name == 'attribute'
return true if method_name == 'attribute_changed?'
return true if method_name == 'attribute_change'
return true if method_name == 'attribute_will_change!'
return true if method_name == 'attribute_was'
return true if method_name == 'attribute_column'
return true if method_name == 'reset_attribute!'
super
end
end
end
但这很乱,当我真正尝试访问表格时,这让我很困惑......
我的其他选择是什么 - 有什么好办法绕过这个小混蛋?
【问题讨论】:
-
或许这个问题的解决方案可以帮到你:stackoverflow.com/questions/5428987/…
-
我以前试过这个:@radcheck = Radcheck.all(:select => 'attribute as attr')。但我仍然得到一个错误:(
标签: ruby-on-rails ruby-on-rails-3 activerecord