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

XMLWordPrintableJSON

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

      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
              Reporter:
              alex-klepa
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: