我使用RestKit 0.20来映射2个实体。这是一对多的关系。
教师< - >> SchoolClass
这是Teacher.h
@class SchoolClass;
@interface Teacher : NSManagedObject
@property (nonatomic, retain) NSString * firstName;
@property (nonatomic, retain) NSString * lastName;
@property (nonatomic, retain) NSNumber * teacherId;
@property (nonatomic, retain) NSSet *teachesClass;
@end
@interface Teacher (CoreDataGeneratedAccessors)
- (void)addTeachesClassObject:(SchoolClass *)value;
- (void)removeTeachesClassObject:(SchoolClass *)value;
- (void)addTeachesClass:(NSSet *)values;
- (void)removeTeachesClass:(NSSet *)values;
@end
这是SchoolClass.h
@interface SchoolClass : NSManagedObject
@property (nonatomic, retain) NSString * classCodeId;
@property (nonatomic, retain) NSString * classDesc;
@property (nonatomic, retain) NSString * classRoom;
@property (nonatomic, retain) Teacher *classTeacher;
@end
关系映射的代码是:
[classMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"teacher" toKeyPath:@"classTeacher" withMapping:teacherMapping]];
结果是在SchoolClass对象中,正确添加了classTeacher属性。但是在Teacher对象中,teachesClass属性都是空的。这是预期的行为还是我错过了什么?
由于 射线
答案 0 :(得分:-1)
现在问题已经消失了。现在所有的关系都很好。不确定到底发生了什么。也许是因为我做了json更改后我为模拟器做了重置。以前json的结果有一个问题,导致关系问题的两个方面。修复后,SchoolClass对象很好但是教师对象有关系问题。现在两个都很好。