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

Updating Realm object without primary key? #254

Open
Tj3n opened this issue May 23, 2016 · 8 comments
Open

Updating Realm object without primary key? #254

Tj3n opened this issue May 23, 2016 · 8 comments

Comments

@Tj3n
Copy link

Tj3n commented May 23, 2016

Hi, I'd like to ask what's the correct way to update a Realm Object that doesn't have primary key in 1 closure? I tried remove + insert but it gave me error, i have to change the insert function to update: false only it works, maybe should include another function for insert without primary key?

@pepicrft
Copy link

Good idea @Tj3n we'll add it.

@thepelican
Copy link

thepelican commented Aug 5, 2016

on the same topic, looks like we cant use update: true in teh insert action... you guys found any way?
The only solution is to remove and then add teh field. Does it mean that realm will interpret it as modification? or like two different actions?

if it was the latter it will never show up in modifications section in the code below:
case .Update(let objects, let deletions, let insertions, let modifications): let deletions = deletions.map { $0 } let insertions = insertions.map { (index: $0, element: objects[$0]) } let modifications = modifications.map { (index: $0, element: objects[$0]) } return ObservableChange.Update(deletions: deletions, insertions: insertions, modifications: modifications) }

@Tj3n
Copy link
Author

Tj3n commented Aug 5, 2016

I end up change the whole insert function with the update: Bool added, so that it will use that parameter for the Realm one inside, cant find extension solution for that since the function is based on extension and protocol already

@thepelican
Copy link

@Tj3n which branch are you using? Cant really find this mantioned change anywhere

@Tj3n
Copy link
Author

Tj3n commented Aug 8, 2016

@thepelican it haven't been implemented yet in the lib, i changed it for my own use only, this depends on the author, he might create another function for that

@pepicrft
Copy link

pepicrft commented Aug 8, 2016

@Tj3n feel free to propose your solution. I'm more than open to discuss it and merge it into the repository. I haven't started working on it yet 😛

@Tj3n
Copy link
Author

Tj3n commented Aug 8, 2016

This is actually a critical for Realm user but it's pretty easy to fix, since CoreData's NSManagedObjectContext: Context doesnt seems to do anything with the insert function, i just change it to func insert<T: Entity>(entity: T, update: Bool) throws and use the update param to pass to the Realm's add function inside it

@thepelican
Copy link

this issue its been closed but its not being resolved

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

3 participants