如何在获取的属性中指定一对多属性? [英] How are to-many attributes specified in a fetched property?

查看:130
本文介绍了如何在获取的属性中指定一对多属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个实体,父和子。父实体与名为children的Child有一对多关系。 Child有一个名为childName的String属性。



我想在Parent上创建一个获取的属性,我们称之为specialChild返回一个具有特定名字的Child,让我们说特别。以下谓词在访问抓取的属性时会返回一个空集:




  • children.childName ==特殊

  • SUBQUERY(children,$ everyChild,ANY $)$ SUB

  • SUBQUERY(children,$ eachChild,$ eachChild.childName =
    Special eachChild.childName =
    Special)。@ count> 0



我相信我不知所措,因为我还是很不熟悉他们。 (我可以找到零文档从苹果关于SUBQUERY)我应该在父提取的属性谓词中指定childName是特殊的孩子?



是的,我调用-refreshObject:mergeChanges:但我仍然收到一个空结果。是,目标实体是Child。



解决方案

你想要的是 parent == $ FETCH_SOURCE AND childName ==Special 。这将获得 childName 为Special且其是查找其特殊子项的对象。



在获取的属性谓词中的属性必须存在于目标实体上。这里的目的地是 Child ,所以你不能使用 children ,因为只存在于



$ FETCH_SOURCE 部分对应于您将使用 self 如果你在代码中写了谓词。没有它,你得到每个特殊的孩子,而不只是那些附加到原始 Parent 。它说,子的 parent 属性必须是查找获取的属性值的特定实例。


I have two entities, Parent and Child. The Parent entity has a to-many relationship to Child named "children." Child has a String attribute named "childName."

I want to make a fetched property on Parent, let's call it "specialChild" that returns a Child with a particular name, let's say "Special". The following predicates return an empty set when I access the fetched property:

  • children.childName == "Special"
  • SUBQUERY(children, $eachChild, $eachChild.childName = "Special").@count > 0
  • SUBQUERY(children, $eachChild, ANY $eachChild.childName = "Special").@count > 0

I believe I'm messing up the predicate somehow, because I'm still pretty inexperienced with them. (and I can find zero documentation from Apple on "SUBQUERY") How am I supposed to specify "the child whose childName is Special" in the Parent's fetched property predicate?

Yes, I am calling -refreshObject:mergeChanges: but I still receive an empty result. Yes, the destination entity is Child.

解决方案

What you want is parent==$FETCH_SOURCE AND childName=="Special". This gets any Child whose childName is "Special" and whose parent is the object looking up its special children.

Attributes in a fetched property predicate must exist on the destination entity. Here the destination is Child, so you can't use children since that only exists on Parent.

The $FETCH_SOURCE part corresponds to where you'd use self if you wrote the predicate in code. Without that you get every special child, not just the ones attached to the originating Parent. It says, the parent attribute of the child must be the specific instance looking up the fetched property value.

这篇关于如何在获取的属性中指定一对多属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆