I have model object implementing Mongoid::Document
model
Mongoid::Document
model has an attribute called name
name
I need to reload only name of model
Is there something shorter than
Model.only(:name).find(model.id).name
like model.reload(:name)
model.reload(:name)
Only rewrite the reload method:
module Mongoid module Document def reload(field = nil) field.nil? ? super() : eval("#{self.class.name}.only(:#{field}).find('#{self.id}').#{field}") end end end
Only rewrite the reload method: