Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有model对象实现Mongoid::Document
model
Mongoid::Document
model有一个属性叫做name
name
name我只需要重新加载model
有没有比
Model.only(:name).find(model.id).name
喜欢model.reload(:name)
model.reload(:name)
只重写reload方法:
module Mongoid module Document def reload(field = nil) field.nil? ? super() : eval("#{self.class.name}.only(:#{field}).find('#{self.id}').#{field}") end end end