问题描述
我想获取与对象A具有多对多关系的对象B(即A - >> B)。我已经记忆中有A.我知道我可以从A获得B对象的NSSet,但最好是对B对象进行获取请求(特别是如果我想在UITableView中按日期排序部分)?
I want to fetch objects B which has a to-many relationship with object A (ie. A -->> B). I already have A in memory. I know I could get a NSSet of the B objects from A, but would it be better to make a fetch request of the B objects (especially if I want to sort sections by date in a UITableView)?
我如何才能提出只获得属于单个对象A的B对象的请求?
How would I make such a request that only gets the B objects belonging to a single object A?
推荐答案
如果您已经持有A的实例,只需通过A的访问者访问相关的B实例。
If you are already holding an instance of A, just access the related B instances through A's accessor.
如果您需要直接获取与a相关的所有B特别是A(你不是在这种情况下),你要为B实体构建一个获取请求,其中一个谓词基于Bs与A的(反)关系。(具体语法将取决于反向关系名称,以及该反转是一对一还是多对。)
If you need to directly fetch all the B's related to a particular A (you don't in this case), you'd build a fetch request for the B entity, with a predicate based on the (inverse) relationship of Bs to A. (The specific syntax will depend on the inverse relationship name, and whether that inverse is a to-one or to-many.)
这篇关于核心数据获取与另一个对象关系的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!