0

我的核心数据中有目录和类别实体

他们有一个多对多的关系

我想获取字段 categoryStatus="active" 并参与 catalogue.categories 的特定类别

什么是正确的谓词?

或没有 fetch > catalogue.categories where categoryStatus=@"active"

c# aCatalogue.categories.Where(c=>c.categoryStatus == "active") 的等价物

我尝试这样的事情,但没有运气

-(NSArray *) CategoryGetListWhereStatusActive4Catalogue:aCatalogue2DisplayCategories
{
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];

NSEntityDescription *entity = [NSEntityDescription entityForName:@"Category" inManagedObjectContext:context];
[fetchRequest setEntity:entity];

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"([catalogues containsObject:%@) AND (categoryStatus == %@)" , aCatalogue2DisplayCategories, @"active"];
[fetchRequest setPredicate:predicate];

return [self performFetch:fetchRequest withContextObject:context];
}
4

2 回答 2

0

像这样的东西?

[NSPredicate predicateWithFormat:@"(ANY catalogues == %@) AND (categoryStatus == %@)",
           aCatalogue, @"active"]
于 2013-10-08T14:59:49.487 回答
0

我认为这应该有效:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(SUBQUERY(catalogues, $catalogues, $catalogues == %@).@count>0) AND (categoryStatus == %@)" , aCatalogue2DisplayCategories, @"active"];

或者

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(ANY catalogues = %@) AND (categoryStatus == %@)" , aCatalogue2DisplayCategories, @"active"];
于 2013-10-08T15:08:19.820 回答