JDG
JDG

Reputation: 540

Realm partial update using createOrUpdate doesn't work

I am trying to use Realm for my iOS app. When updating the local Realm DB using createOrUpate, it rewrites the unprovided properties with default values, rather than keep them unchanged. The Realm I use is up to date, 0.93. Anybody has the same issue?

let realm = RLMRealm.defaultRealm()
realm.beginWriteTransaction()
for matchedUser in matchedUsers {
                    let newMatchedUser = MatchedUser()
                    newMatchedUser.objectId = matchedUser.objectId
                    newMatchedUser.username = matchedUser.username
                    newMatchedUser.email = matchedUser.email
                    newMatchedUser.fullname = matchedUser["fullname"] as! String
                    //they are other properties unprovided here.
MatchedUser.createOrUpdateInDefaultRealmWithValue(newMatchedUser)
                }
                realm.commitWriteTransaction()

Upvotes: 0

Views: 611

Answers (1)

JDG
JDG

Reputation: 540

So, I figured out what the issue was. It turns out you cannot user newMachtedUser to update the DB because it will initialize it first and the default values will be provided for this initialization process. The right way is to using individual values to update, or create an dictionary/array for that update.

Upvotes: 2

Related Questions