Kitura / Swift-Kuery-ORM

An ORM for Swift, built on Codable
Apache License 2.0
212 stars 30 forks source link

Update does not update nil values #54

Closed bagfatnick closed 6 years ago

bagfatnick commented 6 years ago

Context and Description

When I use Model.update, nil values in the variables within the model does not get updated

Environment Details

Mac OS 10.13.6 SwiftKueryORM v0.2.0 SwiftKueryPostgreSQL v1.1.5

Steps to Reproduce

` struct Grade: Codable, Model { var subject: String var score: Int? }

//create gradeA
let gradeA = Grade(subject: "Physics", score: 85) 
var gradeAId = Int()
gradeA.save{ (id: Int?, grade: Grade?, error: RequestError?) in
    ...
    gradeAId = id
    print(id, grade)     //3 Grade(subject: "Physics", score: Optional(85))
}

//update gradeA
let modifiedGradeA = Grade(subject: "Chemistry", score: nil)
modifiedGradeA.update(id: gradeAId) { (grade, error) in
    ...
    print(grade)    //Grade(subject: "Chemistry", score: nil)
}

//check gradeA now
Grade.find(id: gradeAId) { (grade, error) in
    ...
    print(grade)    //Grade(subject: "Chemistry", score: Optional(85))
}

`

Expected vs. Actual Behaviour

EnriqueL8 commented 6 years ago

This had been merged - will be included in the next tag.