25 #import "CoreDataHeaders.h"
27 @implementation NSRelationshipDescription
31 TEST_RELEASE(_destinationEntity);
36 - (NSEntityDescription *) destinationEntity
38 return _destinationEntity;
41 - (void) setDestinationEntity: (NSEntityDescription *) entity
43 [
self _ensureEditableWithReason: _(@"Tried to set the destination "
44 @"entity of a relationship "
46 ASSIGN(_destinationEntity, entity);
49 if (_inverseRelationship != nil)
50 [_inverseRelationship setInverseRelationship: nil];
51 [
self setInverseRelationship: nil];
54 - (NSRelationshipDescription *) inverseRelationship
56 return _inverseRelationship;
59 - (void) setInverseRelationship: (NSRelationshipDescription *) relationship
61 [
self _ensureEditableWithReason: _(@"Tried to set the inverse "
62 @"relationship of a relationship "
66 if (relationship != nil &&
67 ![[_destinationEntity properties] containsObject: relationship])
69 [NSException raise: NSInvalidArgumentException
70 format: _(@"Tried to set inverse relationship which is not in the destination entity.")];
73 _inverseRelationship = relationship;
76 - (NSDeleteRule) deleteRule
81 - (void) setDeleteRule: (NSDeleteRule) rule
83 [
self _ensureEditableWithReason: _(@"Tried to set the delete rule "
84 @"of a relationship already in use")];
93 - (void) setMinCount: (
int) aCount
95 [
self _ensureEditableWithReason: _(@"Tried to set minimum count "
96 @"of a relationship already in use")];
97 if (aCount > _maxCount)
99 [NSException raise: NSInvalidArgumentException
100 format: _(@"Tried to set minimum count of a relationship "
101 @"higher than it's maximum count")];
112 - (void) setMaxCount: (
int) aCount
114 [
self _ensureEditableWithReason: @"Tried to set maximum count "
115 @"of a relationship already in use."];
116 if (aCount < _minCount)
118 [NSException raise: NSInvalidArgumentException
119 format: @"Tried to set maximum count of a relationship "
120 @"lower than it's minimum count."];
128 return (_maxCount > 1);
133 - (id) copyWithZone: (NSZone *) zone
135 NSRelationshipDescription * relationship = [
super copyWithZone: zone];
137 [relationship setDestinationEntity: _destinationEntity];
138 [relationship setInverseRelationship: _inverseRelationship];
139 [relationship setDeleteRule: _deleteRule];
140 [relationship setMaxCount: _maxCount];
141 [relationship setMinCount: _minCount];
148 - (id) initWithCoder: (NSCoder *) coder
150 if ((
self = [super initWithCoder: coder]))
152 if ([coder allowsKeyedCoding])
154 ASSIGN(_destinationEntity, [coder decodeObjectForKey:
155 @"DestinationEntity"]);
156 ASSIGN(_inverseRelationship, [coder decodeObjectForKey:
157 @"InverseRelationship"]);
159 _deleteRule = [coder decodeIntForKey: @"DeleteRule"];
160 _minCount = [coder decodeIntForKey: @"MinCount"];
161 _maxCount = [coder decodeIntForKey: @"MaxCount"];
165 ASSIGN(_destinationEntity, [coder decodeObject]);
166 ASSIGN(_inverseRelationship, [coder decodeObject]);
168 [coder decodeValueOfObjCType: @encode(typeof(_deleteRule))
170 [coder decodeValueOfObjCType: @encode(typeof(_minCount))
172 [coder decodeValueOfObjCType: @encode(typeof(_maxCount))
179 - (void) encodeWithCoder: (NSCoder *) coder
181 [
super encodeWithCoder: coder];
182 if ([coder allowsKeyedCoding])
184 [coder encodeObject: _destinationEntity forKey: @"DestinationEntity"];
185 [coder encodeObject: _inverseRelationship
186 forKey: @"InverseRelationship"];
188 [coder encodeInt: _deleteRule forKey: @"DeleteRule"];
189 [coder encodeInt: _minCount forKey: @"MinCount"];
190 [coder encodeInt: _maxCount forKey: @"MaxCount"];
194 [coder encodeObject: _destinationEntity];
195 [coder encodeObject: _inverseRelationship];
197 [coder encodeValueOfObjCType: @encode(typeof(_deleteRule))
199 [coder encodeValueOfObjCType: @encode(typeof(_minCount))
201 [coder encodeValueOfObjCType: @encode(typeof(_maxCount))