-
Type: Task
-
Resolution: Done
-
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')
=>
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?