views:

18

answers:

1

Hi there,

say i have NSManagedObject A, that has a many-to-many relationship to NSManagedObject B. I have one saved instance of A and B. (not yet related)

Now I want A to save the instance of B twice in its relationship, which is of course a set. Though, since its a set it stores only one reference of B.

see: (not syntax checked)

NSArray *tmpArray = [NSArray arrayWithObjects: B1, B1, nil];
[A setB: [NSSet setWithArray: tmpArray]];

-> only one B is stored in that relationship..

Is it possible to keep track of both B's ?

A: 

You can't do this. Core Data is not maintaining an array but an object-graph.

An object-graph store the relationships between objects. Since each object is unique, it makes no sense to have a duplicate relationship because that conveys no information. Suppose you have an object Person instance Jane that has a brothers relationship which contains three objects, Steve,John and Mike. It would be logically nonsensical to have two relationships to Steve because the real Steve that the object models isn't Jane's brother twice. Even if Jane did have two brothers named Steve, they would still be seperate individuals requiring their own objects to represent them in the object-graph.

If you find yourself thinking you require duplicate relationships, then you've probably misunderstood something about how the object-graph works.

TechZen