views:

29

answers:

1

From the docs:

If all of a managed object's relationship delete rules are Nullify, then for that object at least there is no additional work to do (you may have to consider other objects that were at the destination of the relationship—if the inverse relationship was either mandatory or had a lower limit on cardinality, then the destination object or objects might be in an invalid state).

Does someone have an example of this cardinality thing? What's this good for and what's important to know about this? (sounds very important...)

+2  A: 

The cardinality of an object relationship defines how many objects at the left end are mapped to how many objects at the right end. For example, it can be:

  • 1 : 1 (one to one) - for each object of the left type, exactly one object of the right type is required. In this scenario, usually both objects have a pointer to the other or store the unique id of it.
  • 1 : 1..* (one to many) - for each object of the left type, at least one object of the right type is required, but more can be created. In this scenario, usually the object on the left does not know about the objects on the right, but the objects on the right have a pointer or keep unique id for the left object.
  • 1 : 0..1 (one to optional one) - for each object of the left type, no object of the right type is required, but if any exist, it must be no more than one. In this scenario, usually the object on the left does not know about the objects on the right, but the objects on the right have a pointer or keep unique id for the left object.
  • 1..* : 1..* (many to many) - for each object of the left type, at least one object of the right type is required, but one object of the right type might satisfy the requirement for multiple objects of the left type. In this scenario, usually both objects on the left and right side don't know about the others, but they both have a pointer to a common third object or keep unique id that defines the relationship.
  • etc.

Note that while in all my examples I talk about the relationship of the right object to the left object, each cardinality can be reversed, and some of the cardinalities specify bi-directional requirements (ie. right-to-left and left-to-right)

Here's more information about Cardinality with regards to data models.

In particular, the above paragraph from Core Data states that if you delete an object that is on the right side of a 1 : 1, 1 : 1..* or 1..* : 1..* relationship (in other words, one or more other objects depend on the existence of this particular object), the objects on the left side of such relationship would be in an invalid state.

Franci Penov
Great answer. So if the cardinality is "low" on one end, it means that end has less objects. i.e. a 1:n relationship (one-to-many) would mean that the cardinality on the left is 1, where as the cardinality on the right is n, and thus higher?
dontWatchMyProfile
Yes, that is correct. But how high is the cardinality on particular end usually doesn't matter, as it's used to define the relationship of the objects, not their order.
Franci Penov