On Sep 18, 2010, at 5:41 AM, Amy Gibbs wrote:

> Hi,
> 
> in a core data app, is there an easy way to 'merge' two instances of an 
> entity, for example where something has been accidentally added twice, and 
> each instance has it's own relationships.

There is no "automatic" or "built-in" way, but Core Data makes changing 
relationships easy, so it will likely be easy.

> I'd like to merge the two instances into a single one where basically all of 
> the second instances relationships are copied to the first instance, then the 
> second instance is deleted. In my scenario I think it would be OK to just 
> 'add' the second instances details to the first, I don't see that anything in 
> the second instance would cause data/relationships to be deleted in the first.
> 
> If I have to do this manually, is it that simple, just copy the relationships 
> (not that I know how to do that but it must be possible) and delete the 
> second instance?

How you handle migrating to-many relationships depends on the merge logic you 
need to use. Whether to-one or to-many, if you are replacing object A's 
relationships with object B's, you can use the direct setter method. Otherwise 
for to-many, you can add one at a time using -mutableSetValueForKey:, deciding 
on an object by object basis whether to add or not. Of course, all of this 
assumes a one-way update (versus a sync, which requires knowing additional 
state info).

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to