Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to update only some properties of record? #57

Open
NortromInsanlyDev opened this issue Jun 4, 2021 · 4 comments
Open

How to update only some properties of record? #57

NortromInsanlyDev opened this issue Jun 4, 2021 · 4 comments

Comments

@NortromInsanlyDev
Copy link

How can I update only some properties with keeping old other properties?
Seems like Realm.create(_ : value: update) is not implemented.
Thanks for this awesome repo.

@arturdev
Copy link
Collaborator

arturdev commented Jun 5, 2021

Can you bring an example of what you want to achieve?

@justdan0227
Copy link

Not sure why @NortromInsanlyDev did not supply one but I'll give it a go.

struct myObject {
var name: String
var age: Int
var favPlaces:[String]
}

I just want to update the favPlaces array without having to supply the entire object.

@arturdev
Copy link
Collaborator

Imagine:

var myObj = realm.objects(ofType: MyObject.self).last!

if you update only one property:
myObj.favPlaces = ["SF", "LA"]

and save it to the realm by

try! realm.write {
    realm.add(myObj)
}

It will keep the old properties unchanged

@jlott1
Copy link

jlott1 commented Mar 21, 2022

@arturdev
I think a better example is I have

struct Parent {
    var name: String
    var superPower: String
   var children: [Child] 
}

struct Child {
  var name: String
  var talent: String
 var grandchildren: [Grandchild]
}

struct Grandchild {
  var age: Int
}

Given these data structures, say from my server I fetched an updated list of all of my parents' names and superPowers but didn't want to fetch all of the children and grandchildren because there was no modifications made to those objects. I'd like to have a way to update top-level properties of an array of objects and ignore the relations for those objects. your suggestion is that I have to first fetch the parent objects individually and update each individual property which is not very optimal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants