开发者

How to specify Destination for Core Data fetchRequest programmatically?

Im开发者_Go百科 trying to perform a fetch request programmatically to retrieve certain entities from "EntityA". However i need to set the Destination for the fetch request to "EntityB" for the predicate to work similar to how you would do so through the inspector panel in XC? Cant figure out how to set this property programmatically though?

Thx


Each fetch only has one entity as it's target. The predicate for a fetch can only operate on the attributes and relationships of the target entity. If you want to test a property of another entity, there must be a relationship from the target entity to the other entity.

Suppose you have the following data model:

Alpha{
  name:string
  beta<-->Beta.alpha
}

Beta{
  cost:number
  alpha<-->Alpha.beta
}

Gamma{
  date:date
}

If your target entity for the fetch is Alpha then you can create a predicate that test an attribute of Beta through each Alpha object's beta relationship.

NSPredicate *p=[NSPredicate predicateWithFormat:@"beta.number>5"];

... but you can't create a predicate that will access an attribute of Gamma because there is no relationship.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜