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.
我看到 Mongoid 支持只读属性。有没有办法将整个文档或整个集合/模型类标记为只读?
您可以访问fields类属性并针对attr_readonly. 例如:
fields
attr_readonly
class Model include Mongoid::Document attr_readonly *fields.keys end
请注意,fields.keys将包括_id和_type。
fields.keys
_id
_type