列名

2011-01-11 31 views
2

我有像年权#2,#年权3(可怕的)列名的遗留表...年权#9列名

我建立一个模型,它起名Glamas

如果我有:

accounts = Glamas.all 
account_mains = accounts.collect(&:ACCOUNT_MAIN) 

它打破了这个错误:

SyntaxError: compile error 
/usr/lib/ruby/gems/1.8/gems/activemodel-3.0.3/lib/active_model/attribute_methods.rb:273: syntax error, unexpected kUNDEF, expecting ')' 
        undef :LYEAR#9? 
         ^
/usr/lib/ruby/gems/1.8/gems/activemodel-3.0.3/lib/active_model/attribute_methods.rb:274: syntax error, unexpected kEND, expecting $end 
    from /usr/lib/ruby/gems/1.8/gems/activemodel-3.0.3/lib/active_model/attribute_methods.rb:274:in `define_attribute_methods' 
    from /usr/lib/ruby/gems/1.8/gems/activemodel-3.0.3/lib/active_model/attribute_methods.rb:262:in `each' 
    from /usr/lib/ruby/gems/1.8/gems/activemodel-3.0.3/lib/active_model/attribute_methods.rb:262:in `define_attribute_methods' 
from /usr/lib/ruby/gems/1.8/gems/activemodel-3.0.3/lib/active_model/attribute_methods.rb:261:in `each' 
from /usr/lib/ruby/gems/1.8/gems/activemodel-3.0.3/lib/active_model/attribute_methods.rb:261:in `define_attribute_methods' 
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/attribute_methods.rb:13:in `define_attribute_methods' 
from /usr/lib/ruby/gems/1.8/gems/activerecord-3.0.3/lib/active_record/attribute_methods.rb:41:in `method_missing' 
from (irb):31:in `to_proc' 
from (irb):31:in `collect' 
from (irb):31 
from :0 

这是一个有问题的activemodel,还是我可以用我的代码中的某些东西修复的东西?

这是轨道3 btw。

#glamas.rb 
class Glamas < ActiveRecord::Base 
    establish_connection "turnkey" 
end 

和...

#database.yml 
turnkey: 
    adapter: mysql 
    encoding: utf8 
    reconnect: false 
    database: turnkey 
    pool: 5 
    username: root 
    password: 
    socket: /var/run/mysqld/mysqld.sock 

我从旧机拉表海峡过来,我想(如果我绝对有),当我拉他们了,我可以重命名列,但这个过程已经是一个巨大的痛苦和处理器密集型。

+0

你是如何声明表映射的? – Dogbert 2011-01-11 23:00:37

+0

更新了此信息的问题。 – 2011-01-11 23:05:09

回答

3

你不能在Active Record中使用这些表格。 AR为您的类定义了实例方法,这些实例方法与列名称相同,并且在方法名称(或任何其他名称,因为它是注释字符)中不允许使用红宝石#

我建议或者用更明智的名字在数据库中创建视图,或者只是重命名列。