Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Setting a relationship value for the 'one' side in a one-to-one or a …

…one-to-many relationship now correctly sets the inverse. Fixed an issue where NSSets/NSArrays were retaining their objects even if the relationship was set to transient.
  • Loading branch information...
commit ec7abde6ac24a417e460bdddef386e35d9bcd3ff 1 parent 56906d1
@tyrone-sudeium authored
View
11 contributed templates/Nikita Zhuk/ponso/templates/NSSet/human.h.motemplate
@@ -0,0 +1,11 @@
+//
+// <$managedObjectClassName$>.h
+//
+// $Id$
+//
+
+#import "_<$managedObjectClassName$>.h"
+
+@interface <$managedObjectClassName$> : _<$managedObjectClassName$> <_<$managedObjectClassName$>>
+// Custom logic goes here.
+@end
View
24 contributed templates/Nikita Zhuk/ponso/templates/NSSet/human.m.motemplate
@@ -0,0 +1,24 @@
+//
+// <$managedObjectClassName$>.m
+//
+// $Id$
+//
+
+#import "<$managedObjectClassName$>.h"
+
+@implementation <$managedObjectClassName$>
+
+#pragma mark Abstract method overrides
+
+<$foreach Relationship noninheritedRelationshipsInIDKeyPathTopologicalOrder do$><$if ! Relationship.isTransient$><$if Relationship.userInfo.destinationEntityIDKeyPath $>
+- (<$Relationship.destinationEntity.managedObjectClassName$> *)fetch<$Relationship.destinationEntity.name$>ObjectWithIDFor<$Relationship.name.initialCapitalString$>Relationship:(id)objectID
+{
+ //! TODO: Return an object of type <$Relationship.destinationEntity.managedObjectClassName$>
+ return nil;
+}
+<$endif$><$endif$><$endforeach do$>
+
+
+// Custom logic goes here.
+
+@end
View
52 contributed templates/Nikita Zhuk/ponso/templates/NSSet/machine.h.motemplate
@@ -0,0 +1,52 @@
+//
+// <$managedObjectClassName$>.h
+//
+// $Id$
+//
+// DO NOT EDIT. This file is machine-generated and constantly overwritten.
+// Make changes to <$managedObjectClassName$>.h instead.
+//
+
+
+#import <Foundation/Foundation.h>
+#import "ModelObject.h"
+<$if hasCustomSuperentity$>#import "<$customSuperentity$>.h"<$endif$>
+<$checkNonTransientRelationshipCycles $>
+<$foreach Relationship noninheritedRelationships do$>@class <$Relationship.destinationEntity.managedObjectClassName$>;
+<$endforeach do$>
+
+@protocol _<$managedObjectClassName$>
+<$foreach Relationship noninheritedRelationshipsInIDKeyPathTopologicalOrder do$><$if ! Relationship.isTransient$><$if Relationship.userInfo.destinationEntityIDKeyPath $>
+- (<$Relationship.destinationEntity.managedObjectClassName$> *)fetch<$Relationship.destinationEntity.name$>ObjectWithIDFor<$Relationship.name.initialCapitalString$>Relationship:(id)objectID;
+<$endif$><$endif$><$endforeach do$>
+@end
+
+
+@interface _<$managedObjectClassName$> : <$customSuperentity$>
+{
+ <$foreach Attribute noninheritedAttributes do$><$if Attribute.hasDefinedAttributeType$><$Attribute.objectAttributeType$> *<$Attribute.name$>;<$endif$>
+ <$endforeach do$>
+ <$foreach Relationship noninheritedRelationships do$>
+ <$if Relationship.isToMany$>NSSet *<$Relationship.name$>;<$else$><$Relationship.destinationEntity.managedObjectClassName$> *<$Relationship.name$>;<$endif$>
+ <$endforeach do$>
+}
+
+<$foreach Attribute noninheritedAttributes do$><$if Attribute.hasDefinedAttributeType$>@property (nonatomic, retain, readwrite) <$Attribute.objectAttributeType$> *<$Attribute.name$>;
+<$if Attribute.hasScalarAttributeType$>@property (nonatomic, assign, readwrite) <$Attribute.scalarAttributeType$> <$Attribute.name$>Value;
+<$endif$><$endif$><$endforeach do$>
+<$foreach Relationship noninheritedRelationships do$><$if Relationship.isToMany$>@property (nonatomic, retain, readonly) NSSet *<$Relationship.name$>;
+<$else$><$if Relationship.isTransient $>@property (nonatomic, assign, readwrite) <$Relationship.destinationEntity.managedObjectClassName$> *<$Relationship.name$>;
+<$else$>@property (nonatomic, retain, readwrite) <$Relationship.destinationEntity.managedObjectClassName$> *<$Relationship.name$>;<$endif$>
+<$endif$><$endforeach do$>
+<$foreach Relationship noninheritedRelationships do$>
+<$if Relationship.isToMany$>- (void)add<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_ settingInverse: (BOOL) setInverse;
+- (void)add<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_;
+- (void)remove<$Relationship.name.initialCapitalString$>Objects;
+- (void)remove<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_ settingInverse: (BOOL) setInverse;
+- (void)remove<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_;
+<$endif$><$endforeach do$>
+<$foreach Relationship noninheritedRelationships do$><$if ! Relationship.isToMany$>
+- (void) set<$Relationship.name.initialCapitalString$>: (<$Relationship.destinationEntity.managedObjectClassName$>*) <$Relationship.name$>_ settingInverse: (BOOL) setInverse;
+<$endif$><$endforeach do$>
+
+@end
View
229 contributed templates/Nikita Zhuk/ponso/templates/NSSet/machine.m.motemplate
@@ -0,0 +1,229 @@
+//
+// <$managedObjectClassName$>.m
+//
+// $Id$
+//
+// DO NOT EDIT. This file is machine-generated and constantly overwritten.
+// Make changes to <$managedObjectClassName$>.h instead.
+//
+
+#import "_<$managedObjectClassName$>.h"
+
+<$foreach Relationship noninheritedRelationships do$>#import "<$Relationship.destinationEntity.managedObjectClassName$>.h"
+<$endforeach do$>
+
+@interface _<$managedObjectClassName$>()
+<$foreach Relationship noninheritedRelationships do$><$if Relationship.isToMany$>@property (nonatomic, retain, readwrite) NSSet *<$Relationship.name$>;
+<$endif$><$endforeach do$>
+@end
+
+/** \ingroup DataModel */
+
+@implementation _<$managedObjectClassName$>
+
+- (id)init
+{
+ if((self = [super init]))
+ {
+ <$foreach Attribute noninheritedAttributes do$><$if Attribute.hasDefinedAttributeType$><$if Attribute.hasScalarAttributeType$><$if ! Attribute.isOptional$><$if Attribute.defaultValue$>self.<$Attribute.name$> = [NSNumber numberWith<$Attribute.scalarAttributeType.camelCaseString.initialCapitalString$>:<$Attribute.defaultValue$>];
+ <$else$>self.<$Attribute.name$> = [NSNumber numberWith<$Attribute.scalarAttributeType.camelCaseString.initialCapitalString$>:0];
+ <$endif$><$endif$><$endif$><$endif$><$endforeach do$>
+ }
+
+ return self;
+}
+
+#pragma mark Scalar values
+<$foreach Attribute noninheritedAttributes do$><$if Attribute.hasDefinedAttributeType$><$if Attribute.hasScalarAttributeType$>
+- (<$Attribute.scalarAttributeType$>)<$Attribute.name$>Value
+{
+ return [self.<$Attribute.name$> <$Attribute.scalarAttributeType.camelCaseString$>Value];
+}
+
+- (void)set<$Attribute.name.initialCapitalString$>Value:(<$Attribute.scalarAttributeType$>)value_
+{
+ self.<$Attribute.name$> = [NSNumber numberWith<$Attribute.scalarAttributeType.camelCaseString.initialCapitalString$>:value_];
+}
+<$endif$><$endif$><$endforeach do$>
+
+
+#pragma mark Dictionary representation
+
+- (id)initWithDictionaryRepresentation:(NSDictionary *)dictionary
+{
+ if((self = [super initWithDictionaryRepresentation:dictionary]))
+ {
+ <$foreach Attribute noninheritedAttributes do$><$if Attribute.hasDefinedAttributeType$>self.<$Attribute.name$> = [dictionary objectForKey:@"<$managedObjectClassName$>.<$Attribute.name$>"];
+ <$endif$><$endforeach do$>
+ <$foreach Relationship noninheritedRelationships do$><$if ! Relationship.userInfo.destinationEntityIDKeyPath $><$if ! Relationship.isTransient$><$if Relationship.isToMany$>
+ for(id objectRepresentationForDict in [dictionary objectForKey:@"<$managedObjectClassName$>.<$Relationship.name$>"])
+ {
+ <$Relationship.destinationEntity.managedObjectClassName$> *<$Relationship.name$>Obj = [[[<$Relationship.destinationEntity.managedObjectClassName$> alloc] initWithDictionaryRepresentation:objectRepresentationForDict] autorelease];
+ [self add<$Relationship.name.initialCapitalString$>Object:<$Relationship.name$>Obj];
+ }<$else$>NSDictionary *<$Relationship.name$>Dict = [dictionary objectForKey:@"<$managedObjectClassName$>.<$Relationship.name$>"];
+ if(<$Relationship.name$>Dict != nil)
+ {
+ <$Relationship.destinationEntity.managedObjectClassName$> *<$Relationship.name$>Obj = [[<$Relationship.destinationEntity.managedObjectClassName$> alloc] initWithDictionaryRepresentation:<$Relationship.name$>Dict];
+ self.<$Relationship.name$> = <$Relationship.name$>Obj;
+ [<$Relationship.name$>Obj release];
+ }<$endif$><$endif$><$endif$><$endforeach do$>
+ }
+
+ return self;
+}
+
+- (NSDictionary *)dictionaryRepresentation
+{
+ NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:[super dictionaryRepresentation]];
+ <$foreach Attribute noninheritedAttributes do$><$if Attribute.hasDefinedAttributeType$>[dict setObjectIfNotNil:self.<$Attribute.name$> forKey:@"<$managedObjectClassName$>.<$Attribute.name$>"];
+ <$endif$><$endforeach do$>
+ <$foreach Relationship noninheritedRelationships do$><$if Relationship.isToMany$>if([self.<$Relationship.name$> count] > 0)
+ {
+ <$if (! Relationship.isTransient) or (Relationship.userInfo.destinationEntityIDKeyPath) $>
+ NSMutableSet *<$Relationship.name$>RepresentationsForDictionary = [NSMutableSet setWithCapacity:[self.<$Relationship.name$> count]];
+ for(<$Relationship.destinationEntity.managedObjectClassName$> *obj in self.<$Relationship.name$>)
+ {
+ <$if Relationship.userInfo.destinationEntityIDKeyPath $>[<$Relationship.name$>RepresentationsForDictionary addObject:[obj valueForKeyPath:@"<$Relationship.userInfo.destinationEntityIDKeyPath$>"]];
+ <$else$>[<$Relationship.name$>RepresentationsForDictionary addObject:[obj dictionaryRepresentation]];<$endif$>
+ }
+ [dict setObjectIfNotNil:<$Relationship.name$>RepresentationsForDictionary forKey:@"<$managedObjectClassName$>.<$Relationship.name$>"];
+ <$endif$>
+ }
+ <$else$>
+ <$if Relationship.userInfo.destinationEntityIDKeyPath $>[dict setObjectIfNotNil:[self.<$Relationship.name$> valueForKeyPath:@"<$Relationship.userInfo.destinationEntityIDKeyPath$>"] forKey:@"<$managedObjectClassName$>.<$Relationship.name$>"];
+ <$else$><$if ! Relationship.isTransient $>[dict setObjectIfNotNil:[self.<$Relationship.name$> dictionaryRepresentation] forKey:@"<$managedObjectClassName$>.<$Relationship.name$>"];
+ <$endif$>
+ <$endif$>
+ <$endif$>
+ <$endforeach do$>
+ return dict;
+}
+
+- (void)awakeFromDictionaryRepresentationInit
+{
+ if(self.sourceDictionaryRepresentation == nil)
+ return; // awakeFromDictionaryRepresentationInit has been already executed on this object.
+
+ <$foreach Relationship noninheritedRelationshipsInIDKeyPathTopologicalOrder do$><$if Relationship.userInfo.destinationEntityIDKeyPath $><$if Relationship.isToMany$>NSSet *<$managedObjectClassName$>_<$Relationship.name$>IDs = [self.sourceDictionaryRepresentation objectForKey:@"<$managedObjectClassName$>.<$Relationship.name$>"];
+ for(id <$managedObjectClassName$>_<$Relationship.name$>ID in <$managedObjectClassName$>_<$Relationship.name$>IDs)
+ {
+ <$Relationship.destinationEntity.managedObjectClassName$> *<$Relationship.name$>Obj = [(_<$managedObjectClassName$><_<$managedObjectClassName$>> *)self fetch<$Relationship.destinationEntity.name$>ObjectWithIDFor<$Relationship.name.initialCapitalString$>Relationship:<$managedObjectClassName$>_<$Relationship.name$>ID];
+ if(<$Relationship.name$>Obj != nil)
+ [self add<$Relationship.name.initialCapitalString$>Object:<$Relationship.name$>Obj];
+ }
+ <$else$>self.<$Relationship.name$> = [(_<$managedObjectClassName$><_<$managedObjectClassName$>> *)self fetch<$Relationship.destinationEntity.name$>ObjectWithIDFor<$Relationship.name.initialCapitalString$>Relationship:[self.sourceDictionaryRepresentation objectForKey:@"<$managedObjectClassName$>.<$Relationship.name$>"]];
+ <$if ! Relationship.inverseRelationship.isToMany$>self.<$Relationship.name$>.<$Relationship.inverseRelationship.name$> = (<$managedObjectClassName$>*)self;
+ <$else$>[self.<$Relationship.name$> add<$Relationship.inverseRelationship.name.initialCapitalString$>Object:(<$managedObjectClassName$>*)self];<$endif$>
+
+ <$endif$><$endif$><$endforeach do$>
+
+
+ <$foreach Relationship noninheritedRelationshipsInIDKeyPathTopologicalOrder do$><$if ! Relationship.isTransient$><$if Relationship.destinationEntity != Relationship.entity $><$if Relationship.isToMany$>
+ for(<$Relationship.destinationEntity.managedObjectClassName$> *<$Relationship.name$>Obj in self.<$Relationship.name$>)
+ {
+ [<$Relationship.name$>Obj awakeFromDictionaryRepresentationInit];
+ }
+ <$else$>[self.<$Relationship.name$> awakeFromDictionaryRepresentationInit];
+ <$endif$><$endif$><$endif$><$endforeach do$>
+
+ [super awakeFromDictionaryRepresentationInit];
+}
+
+#pragma mark Direct access
+
+<$foreach Relationship noninheritedRelationships do$><$if Relationship.isToMany$>
+- (void)add<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_ settingInverse: (BOOL) setInverse
+{
+ if(self.<$Relationship.name$> == nil)
+ {
+ <$if Relationship.isTransient$>
+ CFSetCallBacks callbacks = {0, NULL, NULL, CFCopyDescription, CFEqual, CFHash};
+ self.<$Relationship.name$> = [(NSMutableSet*) CFSetCreateMutable(0, 0, &callbacks) autorelease];
+ <$else$>
+ self.<$Relationship.name$> = [NSMutableSet set];
+ <$endif$>
+ }
+
+ [(NSMutableSet *)self.<$Relationship.name$> addObject:value_];
+ <$if Relationship.inverseRelationship$><$if ! Relationship.inverseRelationship.isToMany$>if (setInverse == YES) {
+ [value_ set<$Relationship.inverseRelationship.name.initialCapitalString$>: (<$managedObjectClassName$>*)self settingInverse: NO];
+ }<$endif$><$endif$>
+}
+- (void)add<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_
+{
+ [self add<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_ settingInverse: YES];
+}
+
+- (void)remove<$Relationship.name.initialCapitalString$>Objects
+{
+ <$if Relationship.isTransient$>
+ CFSetCallBacks callbacks = {0, NULL, NULL, CFCopyDescription, CFEqual, CFHash};
+ self.<$Relationship.name$> = [(NSMutableSet*) CFSetCreateMutable(0, 0, &callbacks) autorelease];
+ <$else$>
+ self.<$Relationship.name$> = [NSMutableSet set];
+ <$endif$>
+}
+
+- (void)remove<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_ settingInverse: (BOOL) setInverse
+{
+ <$if Relationship.inverseRelationship$><$if ! Relationship.inverseRelationship.isToMany$>if (setInverse == YES) {
+ [value_ set<$Relationship.inverseRelationship.name.initialCapitalString$>: nil settingInverse: NO];
+ }<$endif$><$endif$>
+ [(NSMutableSet *)self.<$Relationship.name$> removeObject:value_];
+}
+
+- (void)remove<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_
+{
+ [self remove<$Relationship.name.initialCapitalString$>Object:(<$Relationship.destinationEntity.managedObjectClassName$>*)value_ settingInverse: YES];
+}
+
+<$endif$><$endforeach do$>
+
+<$foreach Relationship noninheritedRelationships do$><$if ! Relationship.isToMany$>
+- (void) set<$Relationship.name.initialCapitalString$>: (<$Relationship.destinationEntity.managedObjectClassName$>*) <$Relationship.name$>_ settingInverse: (BOOL) setInverse
+{
+ <$if Relationship.inverseRelationship$><$if Relationship.inverseRelationship.isToMany$>if (<$Relationship.name$>_ == nil && setInverse == YES) {
+ [<$Relationship.name$> remove<$Relationship.inverseRelationship.name.initialCapitalString$>Object: (<$managedObjectClassName$>*)self settingInverse: NO];
+ }<$else$>if (<$Relationship.name$>_ == nil && setInverse == YES) {
+ [<$Relationship.name$> set<$Relationship.inverseRelationship.name.initialCapitalString$>: nil settingInverse: NO];
+ }<$endif$><$endif$>
+ <$if Relationship.isTransient$><$Relationship.name$> = <$Relationship.name$>_;<$else$>if (<$Relationship.name$> != <$Relationship.name$>_) {
+ [<$Relationship.name$> release];
+ <$Relationship.name$> = [<$Relationship.name$>_ retain];
+ }<$endif$>
+ <$if Relationship.inverseRelationship$><$if Relationship.inverseRelationship.isToMany$>if (setInverse == YES) {
+ [<$Relationship.name$> add<$Relationship.inverseRelationship.name.initialCapitalString$>Object: (<$managedObjectClassName$>*)self settingInverse: NO];
+ }<$else$>if (setInverse == YES) {
+ [<$Relationship.name$> set<$Relationship.inverseRelationship.name.initialCapitalString$>: (<$managedObjectClassName$>*)self settingInverse: NO];
+ }<$endif$><$endif$>
+}
+
+- (void) set<$Relationship.name.initialCapitalString$>: (<$Relationship.destinationEntity.managedObjectClassName$>*) <$Relationship.name$>_
+{
+ [self set<$Relationship.name.initialCapitalString$>: <$Relationship.name$>_ settingInverse: YES];
+}
+
+- (<$Relationship.destinationEntity.managedObjectClassName$>*) <$Relationship.name$>
+{
+ return <$Relationship.name$>;
+}
+
+<$endif$><$endforeach do$>
+
+- (void)dealloc
+{
+ <$foreach Attribute noninheritedAttributes do$><$if Attribute.hasDefinedAttributeType$>self.<$Attribute.name$> = nil;
+ <$endif$><$endforeach do$>
+ <$foreach Relationship noninheritedRelationships do$>self.<$Relationship.name$> = nil;
+ <$endforeach do$>
+ [super dealloc];
+}
+
+#pragma mark Synthesizes
+
+<$foreach Attribute noninheritedAttributes do$>@synthesize <$Attribute.name$>;
+<$endforeach do$>
+<$foreach Relationship noninheritedRelationships do$><$if Relationship.isToMany$>@synthesize <$Relationship.name$>;
+<$endif$><$endforeach do$>
+
+@end
Please sign in to comment.
Something went wrong with that request. Please try again.