Ruby mongoid 问题

mjf429 · May 15, 2013 · Last by mjf429 replied at May 15, 2013 · 2945 hits

今天更新了 mongoid 的 master 版本,jbuilder 里的 id 全变成$oid,mongoid 的官方文档说

if you had not been converting your object ids to strings and were storing them in any way that would cause a Marshal dump, you may need to restore these values as strings

然后有个方案是

class Band
  include Mongoid::Document
  field :_id,
    type: String,
    pre_processed: true,
    default: ->{ Moped::BSON::ObjectId.new.to_s }
end

这样做怎么感觉很 2 啊,等于一个数据存了两份,而且 还得进行数据迁移。。。大家有更好的办法吗

用 jbuilder 解决了

def to_builder
  Jbuilder.new do |user|
    user.id id.to_s
  end
end
You need to Sign in before reply, if you don't have an account, please Sign up first.