【发布时间】:2011-03-15 01:51:04
【问题描述】:
我在 Rails 应用程序中有以下模型:
class User
include Mongoid::Document
...
end
class Admin < User
...
end
我得到一个用户:
u = User.find(some_key)
并尝试更改_type:
u._type # => "User"
u._type = "Admin"
u.save
u._type # => "Admin"
但如果我重新加载对象,它仍然是用户:
u.reload
u._type = "User"
正确的方法是什么?
【问题讨论】:
-
它对我来说工作正常(带有类型列)。尝试使用 'type' 字段而不是 '_type'
-
@Ashish 在这里不起作用:u.type #=> NoMethodError: undefined method `type' for #<0x00000104eaf510>0x00000104eaf510>
标签: ruby-on-rails mongodb mongoid