lostintranslation
lostintranslation

Reputation: 24583

How to specify merge policy in magicalrecord

This probably pertains to default CoreData, but since I am using MagicallRecord I am going to ask the question in that context.

I have a couple different places an object can be saved. More specifically an object in one place and its children in another.

Object:

[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
   NSLog(@"saving objects");
   NSArray *objects = // fetch objects with localContext

   // change some data on objects
}];

Children:

[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
   NSLog(@"saving some children");
   NSArray *children = // fetch objects with localContext

   // change some data on children
}];

Nothing really complex, just have a couple different places where I would like to make some modifications in background threads.

What is the right way when using MagicalRecord to specify the merge policy? Do I just set it on each and every localContext?

localContext.mergePolicy = // Whatever merge policy I want

Or should I be setting up a merge policy to be used across my application? IE for now my merge policy is always going to be the same. I know that could change, so I am sure the right answer is to set the merge policy for each and every localContext.

However I have not seen a lot of examples or questions about merge policies with MagicalRecord which really leaves me wondering.

Upvotes: 0

Views: 600

Answers (1)

casademora
casademora

Reputation: 69707

You want to set the merge policy on the context onto which your changes are merging. If you're using the default contexts, those merge policies should be set for you. It also depends on how you're creating the contexts. If they aren't related via parent/child relationships, then you'll have to set up the observation handling manually to merge those changes from one context to another. MR has a helper or two to make that chore easier.

Upvotes: 1

Related Questions