3

我正在使用 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 属性都是空的。这是预期的行为还是我错过了什么?

谢谢雷

4

1 回答 1

-1

不知何故,问题现在消失了。现在所有的关系都运作良好。不确定到底发生了什么。可能是因为我在更改 json 后对模拟器进行了重置。之前json结果有问题导致双方关系出现问题。修复后,SchoolClass 对象正常,但 Teacher 对象存在关系问题。现在两个都很好。

于 2013-03-14T04:25:35.480 回答