RestKit和Core Data问题,并使用谓词获取请求块(删除孤立对象)

时间:2014-02-06 18:13:28

标签: objective-c core-data restkit

我有一个RestKit问题和fetchRequestBlock中的谓词来删除孤立对象。调用fetchRequestBlock,但不删除对象。 我有一个表“metaData”和一个具有多对多关系的表“product”。我希望RestKit删除所有带有metaData.qId == 1的产品,并将其放在fetchRequestBlock的谓词中。如果我使用块中的谓词手动获取数据,我会得到应删除的产品的结果。但RestKit不会删除这些条目。 这是我的代码:

[objectManager addFetchRequestBlock:^NSFetchRequest *(NSURL *URL)
 {
     RKPathMatcher *pathMatcher = [RKPathMatcher pathMatcherWithPattern:@"/api/v1/promotions"];
     NSDictionary *argsDict = nil;
     BOOL match = [pathMatcher matchesPath:[URL relativePath]
                      tokenizeQueryStrings:NO
                           parsedArguments:&argsDict];
     if (match)
     {
         NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Product"];
         fetchRequest.predicate = [NSPredicate predicateWithFormat:@"ANY metaData.qId == 1"];
         fetchRequest.sortDescriptors = @[ [NSSortDescriptor sortDescriptorWithKey:@"productId" ascending:YES] ];             
         return fetchRequest;
     }         
     return nil;
 }];

Core Data中关系中的删除规则设置为“Nullify”。 fetchRequestBlocks谓词中的多对多关系是否存在问题?如果我将谓词设置为ANY metaData = nil,则RestKit会成功删除相应的条目。

有什么想法吗?如果您需要更多信息,请与我们联系。谢谢你的帮助。

更新

以下是产品表中的数据:

product table before request (3 entries):
productId = 113362
productId = 136565
productId = 138688

data received by manually executing fetchRequest in the fetchRequestBlock:
productId = 113362
productId = 136565
productId = 138688

new data received from server:
productId = 113362
productId = 112610
productId = 105622

product table after getting data from the server (5 entries):
productId = 113362
productId = 136565
productId = 138688
productId = 112610
productId = 105622

0 个答案:

没有答案