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

Model#update_attribute allows other attributes' invalid data to be persisted.

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

      An update_attribute called after save will successfully save invalid fields:

      class Person
        include Mongoid::Document
        field :name, :type => String
        field :age, :type => Integer
      
        validates_numericality_of :age
      end
      
      
      p = Person.new(:age => 35)
      p.save!
      
      p => { "_id" : ObjectId("4f4845e6759b51801a000582"), "age" : 35 }
      
      p.age = "infinity"
      if p.save
      	p.update_attribute(:name, "Alex")
      else
      	p.update_attribute(:name, "Hooligan")
      end
      
      p => { "_id" : ObjectId("4f4845e6759b51801a000582"), "age" : "infinity", "name" : "Hooligan" }
      
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            alex-klepa alex-klepa
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: