Reputation: 3250
In core data you can set a relationship to optional but you can set it with minimum checked or without... Check the images below for the difference.
What I think I've noticed is that when you search for an object using a predicate like:@"object != %@", objectToSearchFor
, the first setting returns nil's but the second setting doesn't. I can be mistaken about that but does anybody know the difference between the two settings?
P.s. I don't know if it matters but I'm using SQLite as DB engine.
Upvotes: 4
Views: 1971
Reputation: 539955
There is some documentation about this in the NSRelationshipDescription Class Reference:
Cardinality
The maximum and minimum counts for a relationship indicate the number of objects referenced (1 for a to-one relationship, -1 means undefined). The counts are only enforced if the relationship value in the containing object is not nil. That is, provided that the relationship value is optional, there may be zero objects in the relationship, which might be less than the minimum count.
So for example, in the case of an optional to-many relationship: The value of the relationship must be either nil
, or contain at least the minimum count of required objects.
In the case of an optional to-one relationship, the relationship value either is nil
or points to another object, so I cannot think of a situation where it makes a difference whether the minimum count is 0 or 1.
All the constrains like minimum and maximum count etc. are checked when saving a managed object context.
Upvotes: 5