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 anyChildwhosechildNameis “Special” and whoseparentis 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 usechildrensince that only exists onParent.The
$FETCH_SOURCEpart corresponds to where you’d useselfif you wrote the predicate in code. Without that you get every special child, not just the ones attached to the originatingParent. It says, theparentattribute of the child must be the specific instance looking up the fetched property value.