CoreData add[ttt] vs set[ttt] - difference in to-many relationship?

To clarify things: all of the methods in the interface perform set operations because they all refer to a to-many relationship. The difference between addEmployeeObject: and addEmployees: is that the former adds a single object while the latter adds many of them at the same time. The set operation performed is in this case set union, while for removeEmployeeObject: and removeEmployees it is set difference of course Why you should not think of this in terms of appending to the previous collection of elements already stored?

Because Core Data represents a to-many relationship using a NSSet (a collection of distinct elements), not a NSCountedSet (a set that can contain duplicate elements, also known as a bag). And because a set is an unordered collection therefore "appending" does not make sense (as it does instead for an array or list). Core Data (correctly) does not allow repeated elements stored in the same to-many relationship, therefore the framework uses a NSSet, which enforces distinct elements (while NSCountedSet allows duplicate elements) Finally, when you use the setEmployees: method, you are releasing the current set of employees stored in the to-many relationships and retaining the set you passed as an argument to the setEmployees: method.

Therefore you are changing one-shot the elements stored in the relationship. It is perfectly equivalent to removing first all of the elements stored in the relationship, then adding the new ones (assuming of course they are all distinct).

To clarify things: all of the methods in the interface perform set operations because they all refer to a to-many relationship. The difference between addEmployeeObject: and addEmployees: is that the former adds a single object while the latter adds many of them at the same time. The set operation performed is in this case set union, while for removeEmployeeObject: and removeEmployees it is set difference of course.

Why you should not think of this in terms of appending to the previous collection of elements already stored? Because Core Data represents a to-many relationship using a NSSet (a collection of distinct elements), not a NSCountedSet (a set that can contain duplicate elements, also known as a bag). And because a set is an unordered collection therefore "appending" does not make sense (as it does instead for an array or list).

Core Data (correctly) does not allow repeated elements stored in the same to-many relationship, therefore the framework uses a NSSet, which enforces distinct elements (while NSCountedSet allows duplicate elements). Finally, when you use the setEmployees: method, you are releasing the current set of employees stored in the to-many relationships and retaining the set you passed as an argument to the setEmployees: method. Therefore you are changing one-shot the elements stored in the relationship.It is perfectly equivalent to removing first all of the elements stored in the relationship, then adding the new ones (assuming of course they are all distinct).

Because it takes an NSSet*, presumably neither, unless the original set of Department -to- Employee relationships is empty or disjoint to what you're adding, respectively. Think of these Core Data methods as performing set operations, not array manipulations.As a minor aside, a naming convention is to name to-many relationships with the plural form of the Entity noun (i.e. You might change employee to employees).

This will make more sense to anyone else looking at your methods and Core Data model.

– Alexi Groove Sep 23 '09 at 23:38 I think the -isEqual: method compares the results of the -hash method on both managed objects, I believe. See NSObject for the definition of -hash: developer.apple.Com/mac/library/documentation/Cocoa/Reference/… – Alex Reynolds Sep 24 '09 at 0:09 What I wrote seems like a non-answer, actually. If the MO have different references in them, they may have a different hash result.

It seems easy enough to test this question, though. – Alex Reynolds Sep 24 '09 at 0:11.

To clarify things: all of the methods in the interface perform set operations because they all refer to a to-many relationship. The difference between addEmployeeObject: and addEmployees: is that the former adds a single object while the latter adds many of them at the same time. The set operation performed is in this case set union, while for removeEmployeeObject: and removeEmployees it is set difference of course.

Why you should not think of this in terms of appending to the previous collection of elements already stored? Because Core Data represents a to-many relationship using a NSSet (a collection of distinct elements), not a NSCountedSet (a set that can contain duplicate elements, also known as a bag). And because a set is an unordered collection therefore "appending" does not make sense (as it does instead for an array or list).

Core Data (correctly) does not allow repeated elements stored in the same to-many relationship, therefore the framework uses a NSSet, which enforces distinct elements (while NSCountedSet allows duplicate elements). Finally, when you use the setEmployees: method, you are releasing the current set of employees stored in the to-many relationships and retaining the set you passed as an argument to the setEmployees: method. Therefore you are changing one-shot the elements stored in the relationship.

It is perfectly equivalent to removing first all of the elements stored in the relationship, then adding the new ones (assuming of course they are all distinct).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions