简体   繁体   中英

About NSPredicate in Core Data Fetch

I have two entities, User & Message.

  • Message has a created_at timestamp;
  • Message has a sender[to one relationship with User];
  • User has a sentMessages[to many relationship with Message];

However I want to fetch all users who have sent any messages and with their latest sent message fetched together.

I've try fetch message and set predicate

created_at = sender.sentMessages.@max.created_at

but the compiler told me unable to parse sql statement? How can I do that?

Is that exactly how you called it in your code? The @ operators are keyValue programming operators on collections, so you need to access them via key value semantics. Try:

created_at = [sender valueForKeyPath:@"sentMessages.@max.created_at"];

See

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/KeyValueCoding/Articles/CollectionOperators.html#//apple_ref/doc/uid/20002176-BAJEAIEE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM