环境为 ruby2.0,ruby-oci8 2.1.8, activerecord-oracle_enhanced-adapter 1.5.6。
线下为代码: ———————————————————————————
require 'active_record'
ActiveRecord::Base.establish_connection(:adapter => "oracle_enhanced", :database => "//xxx:1521/orcl", :username => "office", :password => "office")
class User < ActiveRecord::Base
self.table_name = "office_user"
end
user = User.first
#name字段为varchar2(20)类型
puts user.name
#做count没问题,不会报错
#puts User.count
线下为异常情况: —————————————————————————————————
D:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/active_record/att
ribute.rb:104:in `type_cast': undefined method `type_cast_from_database' for "VA
RCHAR2(20)":String (NoMethodError)
from D:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/acti
ve_record/attribute.rb:42:in `original_value'
from D:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/acti
ve_record/attribute.rb:37:in `value'
from D:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/acti
ve_record/attribute_set.rb:31:in `fetch_value'
from D:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/acti
ve_record/attribute_methods/read.rb:93:in `_read_attribute'
from D:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-4.2.1/lib/acti
ve_record/attribute_methods.rb:50:in `__temp__e616d656'
from test_ac.rb:9:in `<main>’