我正在使用 RestKit 0.20 映射 2 个实体。存在一对多关系。
教师<->>学校班级
这是老师.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 对象中,teacherClass 属性都是空的。这是预期的行为还是我错过了什么?
谢谢雷