Hello everyone,
In my project i have NSManagedObjectModel what i have created programmatically and i have two Entity Person and Employee Person has attribute FirstName & LastName Employee has FirstName, LastName & Designation so i want to set Person as a parent entity of Employee it is very easy graphically using .xcdatamodel but i did the whole thing programmatically. so i have to set it programmatically.
this is my full code
now i want to set PersonEntity as parent entity in EmployeeEntity
pls help me how can i do this programmatically or m i getting wrong?
pls help me out pls....
In my project i have NSManagedObjectModel what i have created programmatically and i have two Entity Person and Employee Person has attribute FirstName & LastName Employee has FirstName, LastName & Designation so i want to set Person as a parent entity of Employee it is very easy graphically using .xcdatamodel but i did the whole thing programmatically. so i have to set it programmatically.
this is my full code
Code:
- (NSManagedObjectModel *)managedObjectModel {
if (managedObjectModel != nil) {
return managedObjectModel;
}
managedObjectModel = [[NSManagedObjectModel alloc] init];
NSEntityDescription *personEntity = [[NSEntityDescription alloc] init];
[personEntity setName:@"Person"];
[personEntity setManagedObjectClassName:@"Person"];
[managedObjectModel setEntities:[NSArray arrayWithObject:personEntity]];
[personEntity release];
// Create Properties Array ...i.e. the Columns List
NSMutableArray *personProperties = [NSMutableArray array];
// Create an Attribute ..... i.e. a Column
NSAttributeDescription *firstNameAttribute = [[NSAttributeDescription alloc] init];
[personProperties addObject:firstNameAttribute];
[firstNameAttribute release];
[firstNameAttribute setName:@"firstName"];
[firstNameAttribute setAttributeType:NSStringAttributeType];
[firstNameAttribute setOptional:NO];
NSAttributeDescription *lastNameAttribute = [[NSAttributeDescription alloc] init];
[personProperties addObject:lastNameAttribute];
[lastNameAttribute release];
[lastNameAttribute setName:@"lastName"];
[lastNameAttribute setAttributeType:NSStringAttributeType];
[lastNameAttribute setOptional:NO];
[managedObjectModel setEntities:[NSArray arrayWithObject:personEntity]];
// Create an Entity Object ...i.e. a Table Schema
NSEntityDescription *employeeEntity = [[NSEntityDescription alloc] init];
[employeeEntity setName:@"Employee"];
[employeeEntity setManagedObjectClassName:@"Employee"];
[managedObjectModel setEntities:[NSArray arrayWithObject:employeeEntity]];
[employeeEntity release];
// Create Properties Array ...i.e. the Columns List
NSMutableArray *employeeProperties = [NSMutableArray array];
// Create an Attribute ..... i.e. a Column
NSAttributeDescription *designationAttribute = [[NSAttributeDescription alloc] init];
[employeeProperties addObject:designationAttribute];
[designationAttribute release];
[designationAttribute setName:@"designation"];
[designationAttribute setAttributeType:NSStringAttributeType];
[designationAttribute setOptional:NO];
[employeeEntity setProperties:employeeProperties];
[managedObjectModel setEntities:[NSArray arrayWithObject:employeeEntity]];
return managedObjectModel;
}
now i want to set PersonEntity as parent entity in EmployeeEntity
pls help me how can i do this programmatically or m i getting wrong?
pls help me out pls....