2013-02-25 19 views
1

我有三张表,其关系如下图所示。 随着马克KryzhanouskiCoreData many-to-many relationship)的帮助,我知道如何访问到集合中的所有成分的配方一些:使用CoreData中的连接表获取数据

NSMutableArray* ingredients = [recipe valueForKeyPath:@"ingredients.ingredient"]; 

但我想通过获取访问到的配料表。因为将来我会准备“购物车”功能。

Scheme

我以这种方式

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY count.inRecipe == %@", self.recipe]; 

这样做是正确的吗?

回答

0

简答:是的,它是正确的。

要为配方显示的成分的countinCart性能,你必须要找到加入这是有关配方和成分的对象。

下断言加入实体应该给予这一结果:

NSManagedObject *theIngredient; 
[NSPredicate predicateWithFormat:@"inRecipe == %@ AND ingredient == %@", self.recipe, theIngredient] 
+0

谢谢@马丁,但比我怎样才能获得“数”和“inCart”字段? – Romowski 2013-02-25 10:03:28

+0

@罗莫夫斯基:对不起,但我不明白你的问题。你是否检查谓词是否起作用并给出了预期的结果? – 2013-02-25 10:13:14

+0

是的,谓词工作正常...这个抓取的结果显示在UITableView中,我需要显示** Ingredients.name **和** Join.count **,Join.inCart **单元格** – Romowski 2013-02-25 10:23:01

相关问题