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

Question on dedup/seed/merge #196

Closed
sarunw opened this issue Jan 8, 2015 · 5 comments
Closed

Question on dedup/seed/merge #196

sarunw opened this issue Jan 8, 2015 · 5 comments

Comments

@sarunw
Copy link

sarunw commented Jan 8, 2015

I have 2 questions about ensemble.

First, If my 2 devices got seed data populated on start when it sync the way ensemble handle this from my understanding is it will try to dedup/merge it with - (NSArray *)persistentStoreEnsemble:(CDEPersistentStoreEnsemble *)ensemble globalIdentifiersForManagedObjects:(NSArray *)objects
so if my seed data in this case predefine Category i.e. personal/work will get asked for its identifier and if it has the same global id ensemble will dedup and merge it.

So

Device 1
A----Category A

Device 2
B----Category A

will automatically dedup one and both A/B will point to one of Category A for me

Device 1
A----Category A
B----/

Am I right about this ?

Second question is merge, all this merge and dedup is handle magically under the hood I don't sure if I can have finer grain of control about this. Say I have Parent with many Child and every time child was added to parent, parent will have some computation on all of its children and update property on parent.

Say Parent has latestChild property show the latest child based on Child's createdAt property. This value update every time child was add/remove/edit .
and Child has createdAt property.

If 2 device create child at the slight diff of time say Device 1 create before Device 2 (createdAt are not the same, user can adjust createdAt date on creation).

Device1
Parent A ----- Child A: createdAt 12:00
- latestChild: Child A

Device2
Parent A ------ Child B: createdAt 11:00
- latestChild: Child B

It would finally be

Parent A ------ Child A/ Child B
- latestChild: Child B (due to the fact the Device 2 create later, so let this property from Device 2 win)

If my assumption was right, can I override this behavior ? I want to recalculate latestChild property before merge.

@drewmccormack
Copy link
Owner

You are right about how merging works.

To handle computed values, just implement one of the delegate methods, and update the object in the reparation context before it is saved to the store.

@sarunw
Copy link
Author

sarunw commented Jan 11, 2015

You mean this - (BOOL)persistentStoreEnsemble:(CDEPersistentStoreEnsemble *)ensemble shouldSaveMergedChangesInManagedObjectContext:(NSManagedObjectContext *)savingContext reparationManagedObjectContext:(NSManagedObjectContext *)reparationContext; one right ?

@drewmccormack
Copy link
Owner

Yep. The book explains in merging chapter.

Kind regards,
Drew

On 11 Jan 2015, at 16:46, Sarun Wongpatcharapakorn notifications@github.com wrote:

You mean this - (BOOL)persistentStoreEnsemble:(CDEPersistentStoreEnsemble *)ensemble shouldSaveMergedChangesInManagedObjectContext:(NSManagedObjectContext *)savingContext reparationManagedObjectContext:(NSManagedObjectContext *)reparationContext; one right ?


Reply to this email directly or view it on GitHub.

@pronebird
Copy link
Contributor

pronebird commented Jul 1, 2016

@drewmccormack is shouldSaveMergedChangesInManagedObjectContext a preferred delegate method of manual de-duping before saving changes into persistent store? I am not sure what store reperationContext is connected to, can I fetch stuff inside of it and just delete/merge objects that match both in my CoreData and CDE store at the time of merge? (I have objects that change over time so I cannot assign a single unique ID to them.)

@drewmccormack
Copy link
Owner

You can fetch in the reparation context, yes. It is a child context of the context that is saving.

I think that is indeed to best place to dedupe, but you can also dedupe in the merge completion block.

Kind regards,
Drew

On 01 Jul 2016, at 13:15, Andrei Mihailov notifications@github.com wrote:

@drewmccormack https://github.com/drewmccormack is shouldSaveMergedChangesInManagedObjectContext a preferred way of manual de-duping before saving changes into persistent store? I am not sure what store reperationContext is connected to, can I fetch stuff inside of it and just delete/merge objects that match both in my CoreData and CDE store at the time of merge?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub #196 (comment), or mute the thread https://github.com/notifications/unsubscribe/AAEuAIA5DWCUZmMhS3aoZOnwX3U5BoPOks5qRPa5gaJpZM4DPtAo.

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