Merge pull request #9 from gunyarakun/fix-typo
[cocotron.git] / CoreData / NSRelationshipDescription.m
blob3707ee233bec9bd3ef04a6a797d4f4dfcfec1f7f
1 /* Copyright (c) 2008 Dan Knapp
3 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
8 #import <CoreData/NSRelationshipDescription.h>
9 #import <CoreData/NSEntityDescription.h>
10 #import <Foundation/NSKeyedUnarchiver.h>
12 @implementation NSRelationshipDescription
14 -initWithCoder: (NSCoder *) coder {
15    if(![coder allowsKeyedCoding])
16     [NSException raise: NSInvalidArgumentException format: @"%@ can not initWithCoder:%@", isa, [coder class]];
18    [super initWithCoder:coder];
19    
20    _deleteRule = [coder decodeIntForKey: @"NSDeleteRule"];
21    _destinationEntity = [coder decodeObjectForKey: @"NSDestinationEntity"];
22    _inverseRelationship = [coder decodeObjectForKey: @"NSInverseRelationship"];
23    _optional = [coder decodeBoolForKey: @"NSIsOptional"];
24    _maxCount = [coder decodeIntForKey: @"NSMaxCount"];
25    _minCount = [coder decodeIntForKey: @"NSMinCount"];
26        
27    _destinationEntityName= [coder decodeObjectForKey: @"_NSDestinationEntityName"];
28    _inverseRelationshipName= [coder decodeObjectForKey: @"_NSInverseRelationshipName"];
29        
30    return self;
34 - (NSString *) description {
35     return [NSString stringWithFormat: @"<NSRelationshipDescription: %@->%@>",
36                      _propertyName, _destinationEntityName];
40 - (BOOL) isToMany {
41    return (_minCount==1 && _maxCount==1)?NO:YES;
45 - (int) maxCount {
46     return _maxCount;
50 - (int) minCount {
51     return _minCount;
55 - (NSDeleteRule) deleteRule {
56     return _deleteRule;
60 - (NSEntityDescription *) destinationEntity {
61     return _destinationEntity;
65 - (NSRelationshipDescription *) inverseRelationship {
66     return _inverseRelationship;
70 - (void) setMaxCount: (int) value {
71     if([_entity _hasBeenInstantiated]) {
72         NSLog(@"Attempt to modify entity after instantiating it.");
73         return;
74     }
75     
76     _maxCount = value;
80 - (void) setMinCount: (int) value {
81     if([_entity _hasBeenInstantiated]) {
82         NSLog(@"Attempt to modify entity after instantiating it.");
83         return;
84     }
85     
86     _minCount = value;
90 - (void) setDeleteRule: (NSDeleteRule) value {
91     if([_entity _hasBeenInstantiated]) {
92         NSLog(@"Attempt to modify entity after instantiating it.");
93         return;
94     }
95     
96     _deleteRule = value;
100 - (void) setDestinationEntity: (NSEntityDescription *) value {
101     if([_entity _hasBeenInstantiated]) {
102         NSLog(@"Attempt to modify entity after instantiating it.");
103         return;
104     }
105     
106     _destinationEntity = value;
107     _destinationEntityName = [value name];
111 - (void) setInverseRelationship: (NSRelationshipDescription *) value {
112     if([_entity _hasBeenInstantiated]) {
113         NSLog(@"Attempt to modify entity after instantiating it.");
114         return;
115     }
116     
117     _inverseRelationship = value;
118     _inverseRelationshipName = [value name];
122 @end