Making an entire model read-only with Mongoid

拟墨画扇 提交于 2019-12-07 07:22:23

问题


I see that Mongoid supports read-only attributes. Is there a way to mark an entire document, or an entire collection / model class as read-only?


回答1:


You can access the fields class attribute and splat the hash's keys against attr_readonly. For example:

class Model
  include Mongoid::Document

  attr_readonly *fields.keys
end

Note that, fields.keys will include _id and _type.



来源:https://stackoverflow.com/questions/14573914/making-an-entire-model-read-only-with-mongoid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!