子集的 NSPredicate 查询和“足够接近”子集
一般来说,对 NSPredicates 和核心数据有点陌生,因此尝试掌握我的头脑需要执行以下操作:
我有两个具有多对多关系的实体:
MyContainerEntity code> 包含与 MyObjectEntity
的多对多关系。
假设 MyObjectEntity
的列表为: A、B、C、D、E、F
并且 MyContainerEntity
的组成为:
Container1 - A, B, C
Container2 - B, C, D
Container3 - A, B, D
Container4 - A, D, F
也就是说,Container1 包含与 的关系MyObjectEntity
A、B 和 C 等等。
我想进行一个查询,在其中发送 MyObjectEntity
列表,并返回作为该列表子集的所有 MyContainerEntity
对象。
例如:
(A,B,D,F) 将返回 Container3 和 Container4。
然后,后续操作将得到一些“接近”的结果,并带有一些错误值。假设只有 1 个物体丢失。例如:
(A, B) 将返回 Container1 和 Container3
任何帮助将不胜感激。
Bit new to NSPredicates
and Core Data in general, so trying to grasp my head around need to do the following:
I have two Entities that have a Many-to-many relationship:
MyContainerEntity
contains a many to many relationship with MyObjectEntity
.
Say the list of MyObjectEntity
is: A, B, C, D, E, F
And MyContainerEntity
is made up of:
Container1 - A, B, C
Container2 - B, C, D
Container3 - A, B, D
Container4 - A, D, F
That is, Container1 contains a relationship with MyObjectEntity
A, B and C and so on.
I would like to make a query where I send in a list of MyObjectEntity
and all MyContainerEntity
objects that are a subset of that list are returned.
For example:
(A,B,D,F) would return Container3, and Container4.
Then the follow up would be getting something that is "close" with some error value. Say only 1 object missing. For example:
(A, B) would return Container1 and Container3
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了解决问题的第一部分,您是否尝试定义一个谓词,例如:
其中 OBJECTS_PARAM 值将是一个数组或通过“predicateWithSubstitutionVariables”参数传递给评估的集合?
对于后续问题,我不确定是否可以直接在谓词中进行。看起来在代码中手动实现这样的查询可能比依赖 NSPredicate 更好。
To get the first part of your problem, have you tried defining a predicate such as:
where OBJECTS_PARAM value would be an array or set that you pass into to the evaluation via a "predicateWithSubstitutionVariables" argument?
For the follow up question, I'm not sure if it is possible directly in a predicate. It seems like it might be better to implement such a query manually in code rather than relying on an NSPredicate to do that.