开发者

Sorting an NSFetchRequest Based on a Property within a One-to-Many Relationship?

I've been prowling through the SO search results and can't (thus far) find an answer to this question.

Given a data entity A that has a one-to-many relationship to entity B, is there any way to have my NSFetchedResult sort on a property of entity B. i.e. Can I have my sort descriptor key drill down into entity B? I've tried dot notation, etc, but nothing is working.

e.g. Entity A has a relationship inEntityB. Entity B has a property entityBproperty. How can I sort a list of Entity A's based on the entityBproperty value of their respective inEntityB relationships?

Something like (and no this doesn't work):

request.sortDescriptors = [开发者_运维问答NSArray arrayWithObjects:
    [NSSortDescriptor sortDescriptorWithKey:@"entityAproperty" ascending:NO selector:@selector(localizedStandardCompare:)], 
    [NSSortDescriptor sortDescriptorWithKey:@"inEntityB.entityBproperty" ascending:NO selector:@selector(localizedStandardCompare:)], 
    nil];

It seems awfully inefficient to duplicate, in Entity A, the entityBproperty that I want to sort by. Isn't the whole point of relationships that you can compartmentalize your data model to keep it more manageable?

Any advice much appreciated! Thanks!

Edit: I'm not really sure what additional information I can add to help clarify the question, but given the lack of response thus far, if anyone has suggestions for what else I might add here, I'm all ears. Unfortunately I don't have bounty privileges yet, or I'd consider one in this case, as this seems like a potentially more obscure question.


Looks like a possible duplicate of this question Help sorting an NSArray across two properties (with NSSortDescriptor?)

Unfortunately it seems like there's no easy way to do this with the dot syntax like you have above.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜