列名

2011-01-11 25 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爲您的類定義了實例方法,這些實例方法與列名稱相同,並且在方法名稱(或任何其他名稱,因爲它是註釋字符)中不允許使用紅寶石#

我建議或者用更明智的名字在數據庫中創建視圖,或者只是重命名列。