views:

663

answers:

1

Hello everyone, I have the following 2 Entity’s in my xcdatamodel:

A: 

You need to set the relationship between the new Process and the Matrix.

Check out this answer to iphone core data inserting new objects question.

UPDATE

Assuming that you have generated the class files for Process and Matrix AND Process has a relationship to Matrix named "processToMatrix", the code to set the relationship would be:

newProcess.processToMatrix = matrix;

where "matrix" the the Matrix object that should be associated with the new Process object.

gerry3
I have set the relationship in the xcdatamodel. Is there something I need to add in code to set this relationship between the new Process and Matrix. I appologize for the vagueness but I am new to iphone development.I appreciate your response.
David S
What gets me stunned is the [Airport.Board.flights addObject:newFlight]; line. What would I need to have in this line.
David S
Yes, that's exactly what you need (except you would be adding a Matrix object to that set in your new Process object). The first step is to generate the Class files from the data model.
gerry3
Thanks. This is what I haveMatrix.h#import <CoreData/CoreData.h>@class Process;@interface Matrix : NSManagedObject {}@property (nonatomic, retain) NSString * Name;@property (nonatomic, retain) NSNumber * displayOrder;@property (nonatomic, retain) NSSet* MatrixToProcess;@end@interface Matrix (CoreDataGeneratedAccessors)- (void)addMatrixToProcessObject:(Process *)value;- (void)removeMatrixToProcessObject:(Process *)value;- (void)addMatrixToProcess:(NSSet *)value;- (void)removeMatrixToProcess:(NSSet *)value;@end
David S
Matrix.m#import "Matrix.h"#import "Process.h"@implementation Matrix @dynamic Name;@dynamic displayOrder;@dynamic MatrixToProcess;@end
David S
Process.h#import <CoreData/CoreData.h>@class Objective;@class Matrix;@interface Process : NSManagedObject {}@property (nonatomic, retain) NSString * Name;@property (nonatomic, retain) NSNumber * displayOrder;@property (nonatomic, retain) NSSet* ProcessToObjective;@property (nonatomic, retain) Matrix * ProcessToMatrix;@end
David S
@interface Process (CoreDataGeneratedAccessors)- (void)addProcessToObjectiveObject:(Objective *)value;- (void)removeProcessToObjectiveObject:(Objective *)value;- (void)addProcessToObjective:(NSSet *)value;- (void)removeProcessToObjective:(NSSet *)value;@endProcess.m#import "Process.h"#import "Objective.h"#import "Matrix.h"@implementation Process @dynamic Name;@dynamic displayOrder;@dynamic ProcessToObjective;@dynamic ProcessToMatrix;@end
David S
Can you delete these comments with code? There are not useful. If you have more code, edit your original question and add it there. Also, you may to format your question's code so that it is readable.
gerry3
I just realized that you have a to-one relationship from Process to Matrix (rather than to-many), so you just need to set that property to the appropriate Matrix object (rather than adding the Matrix object to a set).
gerry3
Would this code be correct? Specifically the line for:[self setValue:Process forKey:@"Matrix"];Process *newProcess = [NSEntityDescription insertNewObjectForEntityForName:@"Process" inManagedObjectContext:self.managedObjectContext]; [self setValue:Process forKey:@"Matrix"];
David S
It would be more like (assuming the Matrix object is named "matrix"): newProcess.ProcessToMatrix = matrix
gerry3
Again, can you PLEASE delete these comments with code? They are not useful. If you have more code, edit your original question and add it there. Also, PLEASE fix the formatting of the code in your question!
gerry3