Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-5072

Document readonly attributes ignoring assignment

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 8.0.1
    • Attributes
    • 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

          Activity

            People

              neil.shweky@mongodb.com Neil Shweky (Inactive)
              oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: