Document readonly attributes ignoring assignment

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major - P3
    • 8.0.1
    • Affects Version/s: None
    • Component/s: Attributes
    • None
    • None
    • Fully Compatible
    • None
    • None
    • None
    • None
    • None
    • None

      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.

            Assignee:
            Neil Shweky (Inactive)
            Reporter:
            Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: