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.