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

Raise Mongoid::Errors::ReadonlyDocument when saving readonly documents

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 8.1.0
    • Affects Version/s: 8.0.2
    • Component/s: Persistence
    • Fully Compatible

      There are two steps to this ticket:
      when readonly? is true, prohibit saving/updating the document
      change readonly? to be true, only when readonly! is called

      The current implementation of readonly? is:

      def readonly?
          __selected_fields != nil
      end
      

      Original Ticket
      --------------
      example

       

      class Foo
        include Mongoid::Document
      
        field :name, type: String
      
        def readonly?
          true
        end
      
      end
      
      x = Foo.create(name: 'test')
      x.name = 'something else'
      x.save
      # true
      # expected to raise a Mongoid::Errors::ReadonlyDocument exception
      

      while

      x = Foo.create(name: 'test')
      x.destroy
      

      properly raises an Mongoid::Errors::ReadonlyDocument exception

      possibly related to https://jira.mongodb.org/browse/MONGOID-5072

            Assignee:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Reporter:
            vitasek@tqsoft.de Ralf Vitasek
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: