开发者

Sorting based on one of many related entities

Entity B (Book) has a one-to-many relationship with the entity D (Description). The idea is that a book has different descriptions for different languages.

I want to sort books based on their titles (D.title) for a given language (D.languageID)

If B had one-to-one relationship to D, I would do something like:

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"d.title" ascending:YES];

Of course, you may开发者_StackOverflow say, the model does not prevent a book from having many descriptions with the same languageID. But in this case any (e.g. the first) description would be ok for me.

Is my model wrong? What's the best solution now?


This is logically not possible. If you have many objects B belonging to A, which B is the sort routine supposed to take?

For example you have the entity A "Parent" and the entity B "Child" and the attribute of B "dateOfBirth". You cannot sort all Parent objects according to the lowest birth date because if two different parents have two children each, it is possible that each of them has a child that is older than one of the other's.

Clear?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜