NSRelationshipDescription Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/CoreData.framework
Availability
Available in OS X v10.4 and later.
Companion guide
Declared in
NSRelationshipDescription.h

Overview

The NSRelationshipDescription class is used to describe relationships of an entity in an NSEntityDescription object.

NSRelationshipDescription extends NSPropertyDescription to describe features appropriate to relationships, including cardinality (the number of objects allowed in the relationship), the destination entity, and delete rules.

Cardinality

The maximum and minimum counts for a relationship indicate the number of objects referenced (1/1 for a to-one relationship, 0 means undefined). The counts are only enforced if the relationship value in the containing object is not nil. That is, optional relationships may have zero objects in the relationship, which might be less than the minimum count.

Editing Relationship Descriptions

Relationship descriptions are editable until they are used by an object graph manager. This allows you to create or modify them dynamically. However, once a description is used (when the managed object model to which it belongs is associated with a persistent store coordinator), it must not (indeed cannot) be changed. This is enforced at runtime: any attempt to mutate a model or any of its sub-objects after the model is associated with a persistent store coordinator causes an exception to be thrown. If you need to modify a model that is in use, create a copy, modify the copy, and then discard the objects with the old model.

Tasks

Managing Type Information

Getting and Setting Delete Rules

Cardinality

Ordering

Versioning Support

Instance Methods

deleteRule

Returns the delete rule of the receiver.

- (NSDeleteRule)deleteRule
Return Value

The receiver’s delete rule.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSRelationshipDescription.h

destinationEntity

Returns the entity description of the receiver's destination.

- (NSEntityDescription *)destinationEntity
Return Value

The entity description for the receiver's destination.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSRelationshipDescription.h

inverseRelationship

Returns the relationship that represents the inverse of the receiver.

- (NSRelationshipDescription *)inverseRelationship
Return Value

The relationship that represents the inverse of the receiver.

Discussion

Given a to-many relationship “employees” between a Department entity and an Employee entity (a department may have many employees), and a to-one relationship “department” between an Employee entity and a Department entity (an employee may belong to only one department), the inverse of the “department” relationship is the “employees” relationship.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSRelationshipDescription.h

isOrdered

Returns a Boolean value that indicates whether the receiver describes an ordered relationship.

- (BOOL)isOrdered
Return Value

YES if the relationship is ordered, otherwise NO.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSRelationshipDescription.h

isToMany

Returns a Boolean value that indicates whether the receiver represents a to-many relationship.

- (BOOL)isToMany
Return Value

YES if the receiver represents a to-many relationship (its maxCount is greater than 1) otherwise NO.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSRelationshipDescription.h

maxCount

Returns the maximum count of the receiver.

- (NSUInteger)maxCount
Return Value

The maximum count of the receiver.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSRelationshipDescription.h

minCount

Returns the minimum count of the receiver.

- (NSUInteger)minCount
Return Value

The minimum count of the receiver.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSRelationshipDescription.h

setDeleteRule:

Sets the delete rule of the receiver.

- (void)setDeleteRule:(NSDeleteRule)rule
Parameters
rule

The delete rule for the receiver.

Special Considerations

This method raises an exception if the receiver’s model has been used by an object graph manager.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSRelationshipDescription.h

setDestinationEntity:

Sets the entity description for the receiver's destination.

- (void)setDestinationEntity:(NSEntityDescription *)entity
Parameters
entity

The destination entity for the receiver.

Special Considerations

This method raises an exception if the receiver’s model has been used by an object graph manager.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSRelationshipDescription.h

setInverseRelationship:

Sets the inverse relationship of the receiver.

- (void)setInverseRelationship:(NSRelationshipDescription *)relationship
Parameters
relationship

The inverse relationship for the receiver.

Special Considerations

This method raises an exception if the receiver’s model has been used by an object graph manager.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSRelationshipDescription.h

setMaxCount:

Sets the maximum count of the receiver.

- (void)setMaxCount:(NSUInteger)maxCount
Parameters
maxCount

The maximum count of the receiver.

Special Considerations

This method raises an exception if the receiver’s model has been used by an object graph manager.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSRelationshipDescription.h

setMinCount:

Sets the minimum count of the receiver.

- (void)setMinCount:(NSUInteger)minCount
Parameters
minCount

The minimum count of the receiver.

Special Considerations

This method raises an exception if the receiver’s model has been used by an object graph manager.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSRelationshipDescription.h

setOrdered:

Sets whether the receiver describes an ordered relationship.

- (void)setOrdered:(BOOL)flag
Parameters
flag

YES to indicate that the relationship is ordered, otherwise NO.

Special Considerations

This method raises an exception if the receiver’s model has been used by an object graph manager.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSRelationshipDescription.h

versionHash

Returns the version hash for the receiver.

- (NSData *)versionHash
Return Value

The version hash for the receiver.

Discussion

The version hash is used to uniquely identify an attribute based on its configuration. This value includes the versionHash information from NSPropertyDescription, the name of the destination entity and the inverse relationship, and the min and max count.

Availability
  • Available in OS X v10.5 and later.
See Also
Declared In
NSRelationshipDescription.h

Constants

NSDeleteRule

These constants define what happens to relationships when an object is deleted.

typedef enum {
   NSNoActionDeleteRule,
   NSNullifyDeleteRule,
   NSCascadeDeleteRule,
   NSDenyDeleteRule
} NSDeleteRule;
Constants
NSNoActionDeleteRule

If the object is deleted, no modifications are made to objects at the destination of the relationship.

If you use this rule, you are responsible for maintaining the integrity of the object graph. This rule is strongly discouraged for all but advanced users. You should normally use NSNullifyDeleteRule instead.

Available in OS X v10.4 and later.

Declared in NSRelationshipDescription.h.

NSNullifyDeleteRule

If the object is deleted, back pointers from the objects to which it is related are nullified.

Available in OS X v10.4 and later.

Declared in NSRelationshipDescription.h.

NSCascadeDeleteRule

If the object is deleted, the destination object or objects of this relationship are also deleted.

Available in OS X v10.4 and later.

Declared in NSRelationshipDescription.h.

NSDenyDeleteRule

If the destination of this relationship is not nil, the delete creates a validation error.

Available in OS X v10.4 and later.

Declared in NSRelationshipDescription.h.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSRelationshipDescription.h