Closed sarunw closed 9 years ago
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.
You mean this - (BOOL)persistentStoreEnsemble:(CDEPersistentStoreEnsemble *)ensemble shouldSaveMergedChangesInManagedObjectContext:(NSManagedObjectContext *)savingContext reparationManagedObjectContext:(NSManagedObjectContext *)reparationContext;
one right ?
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.
@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.)
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 https://github.com/drewmccormack/ensembles/issues/196#issuecomment-229921920, or mute the thread https://github.com/notifications/unsubscribe/AAEuAIA5DWCUZmMhS3aoZOnwX3U5BoPOks5qRPa5gaJpZM4DPtAo.
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 predefineCategory
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
will automatically dedup one and both A/B will point to one of Category A for me
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 manyChild
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
haslatestChild
property show the latest child based on Child's createdAt property. This value update every time child was add/remove/edit . andChild
hascreatedAt
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).
It would finally be
If my assumption was right, can I override this behavior ? I want to recalculate latestChild property before merge.