0

記事とカテゴリの 2 つのエンティティがあります。

//Article mapping
RKManagedObjectMapping *categoryMapping = [RKManagedObjectMapping mappingForClass:[Category class] inManagedObjectStore: objectManager.objectStore];
categoryMapping.primaryKeyAttribute = @"categoryId";
[categoryMapping mapKeyPathsToAttributes:
 @"CategoryId",@"categoryId",
 @"CategoryName",@"categoryName",
 nil];

//Category mapping
RKManagedObjectMapping *articleMapping = [RKManagedObjectMapping mappingForClass:[Article class] inManagedObjectStore: objectManager.objectStore];
articleMapping.primaryKeyAttribute = @"articleId";
[articleMapping mapKeyPathsToAttributes:
 @"ArticleId",@"articleId",
 @"ArticleName",@"articleName",
 @"ArticleText",@"articleText",
 @"CategoryId",@"categoryId",
 nil];

//relationship mapping
[categoryMapping mapRelationship:@"articles" withMapping:articleMapping];
[articleMapping mapRelationship:@"category" withMapping:categoryMapping];
[articleMapping connectRelationship:@"category" withObjectForPrimaryKeyAttribute:@"categoryId"];

//set mapping
[objectManager.mappingProvider setMapping:articleMapping forKeyPath:@"article"];
[objectManager.mappingProvider setMapping:categoryMapping forKeyPath:@"category"];

次に、記事のカテゴリを知りたいのですが、null に等しい:

   Article* article = [[Article allObjects] objectAtIndex:0];
   //article.category == nil

article.categoryId と category.categoryId は同じです。

マッピング関係が機能しないのはなぜですか?

4

1 に答える 1