随笔 - 121  文章 - 1 评论 - 21 trackbacks - 3

ruby中,使用activerecord生产的数据访问类,结果出现如标题的错误
“This error is raised because the column 'type' is reserved for storing the class in case of inheritance”

google了下,原来是表中有type这个字段,而type应该是被ruby或者是activerecord作为一个保留字之类的,所以出现这个错误

需要的做法是,给改个别名来访问

 

Code
class Rdevice < ActiveRecord::Base
 set_table_name 
"devices"
 set_inheritance_column :ruby_type

 
# getter for the "type" column
 def device_type
  self[:type]
 end

 
# setter for the "type" column
 def device_type=(s)
  self[:type] 
= s
 end
end

 

这样基本可以搞定

posted on 2009-10-19 20:21 foward.molly.宝儿 阅读(49) 评论(0) 编辑 收藏