请帮我制作正确的抓取请求。 我想获取所有请求,其中rates.identRater!=' someIdent' 我尝试使用谓词:
[NSPredicate predicateWithFormat:@"!(ANY rates.identRater == %@)", identRater]
[NSPredicate predicateWithFormat:@"NONE rates.identRater == %@", identRater]
[NSPredicate predicateWithFormat:@"!(%@ IN rates.identRater)", identRater]
@property (nonatomic, retain) NSString * additionalInfo;
@property (nonatomic, retain) NSNumber * duplicate;
@property (nonatomic, retain) NSDecimalNumber * date;
@property (nonatomic, retain) NSDecimalNumber * dateAccept;
@property (nonatomic, retain) NSDecimalNumber * dateCreate;
@property (nonatomic, retain) NSDecimalNumber * dateChanged;
@property (nonatomic, retain) NSDecimalNumber * dateOfSale;
@property (nonatomic, retain) NSString * fio;
@property (nonatomic, retain) NSString * ident;
@property (nonatomic, retain) NSString * identChanger;
@property (nonatomic, retain) NSString * identOwner;
@property (nonatomic, retain) NSString * identSelectedRate;
@property (nonatomic, retain) NSString * phone;
@property (nonatomic, retain) NSString * status;
@property (nonatomic, retain) Rates *selectedRate;
@property (nonatomic, retain) RequestCar *car;
@property (nonatomic, retain) RequestExterior *exterior;
@property (nonatomic, retain) RequestBundling *bundling;
@property (nonatomic, retain) RequestInterior *interior;
@property (nonatomic, retain) RequestNewCar *theNewCar;
@property (nonatomic, retain) RequestTestdrive *testDrive;
@property (nonatomic, retain) RequestFinalRate *finalRate;
@property (nonatomic, retain) Users *owner;
@property (nonatomic, retain) NSSet *viewedToRate;
@property (nonatomic, retain) NSSet *hiddenToRate;
@property (nonatomic, retain) NSSet *photos;
@property (nonatomic, retain) NSSet *diagnosticPhotos;
@property (nonatomic, retain) NSSet *rates;
@property (nonatomic, retain) NSDecimalNumber * cost;
@property (nonatomic, retain) NSDecimalNumber * costOfSale;
@property (nonatomic, retain) NSString * securityComment;
@property (nonatomic, retain) NSDecimalNumber * dateChanged;
@property (nonatomic, retain) NSString * ident;
@property (nonatomic, retain) NSString * identManager;
@property (nonatomic, retain) NSString * identRater;
@property (nonatomic, retain) NSString * identRequest;
@property (nonatomic, retain) NSDecimalNumber * date;
@property (nonatomic, retain) Requests *request;
@property (nonatomic, retain) Users *rater;
@property (nonatomic, retain) ViewedToRateRequests *viewed;
@property (nonatomic, retain) HiddenToRateRequests *hidden;
@property (nonatomic, retain) Requests *selectedInRequest;
NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
[fetch setEntity:[NSEntityDescription entityForName:@"Requests" inManagedObjectContext:moc]];
[fetch setPredicate:[NSPredicate predicateWithFormat:@"!(ANY rates.identRater == %@)", @"someIdent"]];
[fetch setSortDescriptors:@[[[NSSortDescriptor alloc] initWithKey:@"dateChanged" ascending:YES]]];
如果我使用上面列出的任何谓词,CoreData会返回0行..但我希望看到1行..
请帮帮我..
答案 0 :(得分:2)
你走在正确的轨道上。它是需要调整的字符串比较运算符。而且我认为你的想法2是说明你意图的最直接方式。
[NSPredicate predicateWithFormat:@"NONE rates.identRater LIKE %@", identRater];
(我还没有测试过这个)。
答案 1 :(得分:1)
这应该有效:
[NSPredicate predicateWithFormat:@"SUBQUERY(rates, $r, $r.identRater == %@).@count == 0", identRater]
似乎其他选项无法正常工作,因此子查询是唯一的解决方案:Core Data NSPredicate with to-Many Relationship