0

我正在从 rails 控制台对此进行测试:

Credential.last.token => nil
Credential.last.update_attribute :token, '123'   => true
Credential.last.token => nil

这是我的课:

class Credential
  include Mongoid::Document
  include Mongoid::Timestamps

  field :_id,              type: String
  field :user_id,          type: Integer
  field :code,             type: String
  field :provider,         type: String
  field :token,            type: String

end

我究竟做错了什么?

4

2 回答 2

1

如果您启用了身份映射,则需要将其包装在

Mongoid.unit_of_work { Credential.last.token }

Mongoid 缓存查询。对于 Web 请求来说这不是问题,但是在控制台中您不会看到更改,除非您在工作单元块中执行此操作,或者重新启动控制台(不仅仅是重新加载)

于 2013-01-27T00:14:14.277 回答
0

我不得不把

attr_accessor :token, ...
于 2013-01-27T00:52:23.347 回答