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
.