Core Data: Predicate for first element in orderd relationship

六月ゝ 毕业季﹏ 提交于 2019-11-28 10:07:29

问题


I have this to-many relationship which contains at least one element:

Appointment <<------>> Invitee

appointment.invitees is an ordered relationship resulting in an NSOrderedSet.

In a table view controlled by a fetched results controller, I have the appointments listed, along with the first element of the invitees set.

Now I want to search this list by invitees' names, using an NSPredicate. But how can refer to the first element of the ordered list in the predicate?

I tried:

fetchRequest.predicate = [NSPredicate predicateWithFormat:
       @"invitees[FIRST].lastName CONTAINS[cd] %@", searchTerm];

but I get the unimplemented SQL generation for predicate error. This would make sense, as the result is a collection, but not strictly an array. Still, I think that the sqlite store must be modeling the order, so it should be retrievable.

Any advice?


回答1:


Clearly, this a question that not even the most expert Core Data savants can answer.

The workaround is to model the first element as a separate to-one relationship and the rest as an optional to-many relationship based on the same related entity.

Appointment <<------>  mainInvitee        (Invitee)
            <<------>> additionalInvitees (Invitee)


来源:https://stackoverflow.com/questions/13394513/core-data-predicate-for-first-element-in-orderd-relationship

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!