所以我可以使用以下代码进行连接,但表中有大约200列。我只对2或3感兴趣(例如id,name,location)。
如何手动将这些定义为模型的有效列?
class Legacy < ActiveRecord::Base
establish_connection({
:adapter => "postgresql",
:host => "localhost",
:username => "myUser",
:password => "myPass",
:database => "legacy_db"
})
self.table_name = 'account'
end
答案 0 :(得分:0)
在这里回答:Restrict the columns represented in ActiveRecord
class MyModel < ActiveRecord::Base
default_scope select("column1, column2, column3")
...
end