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

update_all with readonly attribute

    • Type: Icon: Task Task
    • Resolution: Done
    • 12_01_17
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      I have problem when I am trying to use update_all method on field which is readonly.

      My User model is -

      class User
      include Mongoid::Document
      field :name, type: String
      attr_readonly :name
      end

      NOTE: Here name is readonly attribute

      When I am trying to use update_all it is allowing me to update value of readonly field

      2.1.3 :017 > User.all.to_a
      => #<User _id: 54e855837368773ff7000000, name: "Shweta">, #<User _id: 54e855877368773ff7010000, name: "Anuja">

      2.1.3 :018 > User.where(name: 'Shweta').update_all(name: 'Shweta k')
      =>

      {"updatedExisting"=>true, "n"=>1, "connectionId"=>20, "err"=>nil, "ok"=>1.0}

      2.1.3 :019 > User.all.to_a
      => #<User _id: 54e855837368773ff7000000, name: "Shweta k">, #<User _id: 54e855877368773ff7010000, name: "Anuja">

      When I am using update_attribute, Its giving me ReadonlyAttribute error

      2.1.3 :021 > User.first.update_attribute(:name, 'Shweta')
      Mongoid::Errors::ReadonlyAttribute:

      Is this a bug or I am missing something?

            Assignee:
            Unassigned Unassigned
            Reporter:
            Shwetakale Shwetakale [X]
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: