Ios 在具有关系的实体中添加数据
在我的核心数据模型中,我有这样的关系(见图) 现在 我已经像这样声明了这两个实体 问题:-Ios 在具有关系的实体中添加数据,ios,database,core-data,entity-relationship,iphonecoredatarecipes,Ios,Database,Core Data,Entity Relationship,Iphonecoredatarecipes,在我的核心数据模型中,我有这样的关系(见图) 现在 我已经像这样声明了这两个实体 问题:- 由于我已经声明了房间的对象和位置,首先我需要填充 位置的数据,然后我需要填写房间和房间的数据 那么我需要在定位方法中添加房间?对吗 如果我有大数据呢?每次我都需要添加对象,或者是否有任何自定义支持的类可以连接 答复 在这里,顺序并不重要,而是对其他实体对象的引用。你可以直接使用代码 [locObj addWithRoomObject:roomObj]; roomObj.withLocation = loc
[locObj addWithRoomObject:roomObj];
roomObj.withLocation = locObj;
[locObj addWithRoomObject:roomObj];
Location *locObj = [NSEntityDescription insertNewObjectForEntityForName:@"Location"
inManagedObjectContext [self managedObjectContext]];
locObj.locationName = LOCATION_NAME;
Room *room1 = [NSEntityDescription insertNewObjectForEntityForName:@"Room"
inManagedObjectContext:[self managedObjectContext]];
// Fill room1 details
...
room1.withLocation = locObj;
[locObj addWithRoomObject:room1];
Room *room2 = [NSEntityDescription insertNewObjectForEntityForName:@"Room"
inManagedObjectContext:[self managedObjectContext]];
// Fill room2 details
...
room2.withLocation = locObj;
[locObj addWithRoomObject:room2];
// so on..
如何在这里添加一个->多个连接?如何在同一位置添加两个以上的房间?
Location *locObj = [NSEntityDescription insertNewObjectForEntityForName:@"Location"
inManagedObjectContext [self managedObjectContext]];
locObj.locationName = LOCATION_NAME;
Room *room1 = [NSEntityDescription insertNewObjectForEntityForName:@"Room"
inManagedObjectContext:[self managedObjectContext]];
// Fill room1 details
...
room1.withLocation = locObj;
[locObj addWithRoomObject:room1];
Room *room2 = [NSEntityDescription insertNewObjectForEntityForName:@"Room"
inManagedObjectContext:[self managedObjectContext]];
// Fill room2 details
...
room2.withLocation = locObj;
[locObj addWithRoomObject:room2];
// so on..