简体   繁体   English

在NSSet的NSSet上进行核心数据查询

[英]Core data query on a NSSet of NSSet

I'm struggling with core data... I don't understand some things so if someone could help me, I would be very grateful! 我正在努力处理核心数据...我不了解某些事情,所以如果有人可以帮助我,我将非常感激! I have an entity (Recipe) with a relationship to-many with another one (Meal). 我有一个实体(配方),与另一个实体(餐)有很多关系。 I would like to select all the recipes which have no connection with a meal... so I've tried: 我想选择所有与用餐无关的食谱...所以我尝试了:

Code: 码:

[myRecipes filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"meal=%@", nil]]; [myRecipesfilteredSetUsingPredicate:[NSPredicate predicateWithFormat:@“ meal =%@”,无]]];

But it doesn't work... it crashes. 但这不起作用...它崩溃了。

When I look at the SQL database under recipe I don't see meal (I think it's because it's a to-many relationship). 当我查看配方下的SQL数据库时,我没有看到进餐(我认为是因为这是一对多的关系)。 How can I make it? 我该怎么做?

Thanks 谢谢

According to this question 根据这个问题

To test for an empty relationship you should compare the count of the to-many key to zero. 要测试空关系,您应该将“ to-many”键的计数与零进行比较。

For example, 例如,

[NSPredicate predicateWithFormat:@"meal.@count == 0"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM