I have model
object implementing Mongoid::Document
model
has an attribute called 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)
I have model
object implementing Mongoid::Document
model
has an attribute called 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)
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