Details
-
Bug
-
Status: Closed
-
Major - P3
-
Resolution: Fixed
-
None
-
None
-
Fully Compatible
Description
https://docs.mongodb.com/mongoid/master/tutorials/mongoid-documents/#read-only-attributes says:
You can tell Mongoid that certain attributes are read-only. This will allow documents to be created with these attributes, but changes to them will be ignored when using mass update methods such as update_attributes:
Individual assignment appears to be equally ignored:
band = Band.create(name: "Placebo")
|
=> #<Band _id: 6064c0b62c97a64f8c38172b, name: "Placebo", origin: nil>
|
irb(main):074:0> band.name='x'
|
=> "x"
|
irb(main):075:0> band
|
=> #<Band _id: 6064c0b62c97a64f8c38172b, name: "Placebo", origin: nil>
|
irb(main):076:0> band.name
|
=> "Placebo"
|
The individual assignment should either raise ReadonlyAttribute instead of being ignored like that or this behavior should be documented.
Alternatively, if this is the desired behavior, adding a use case to documentation would help clarify when one should use read-only attributes.
Attachments
Issue Links
- related to
-
MONGOID-5059 `set` nilifies attributes excluded via `only`
-
- Closed
-