On Dec 14, 2011, at 12:32 PM, Keary Suska wrote: > On Dec 14, 2011, at 9:46 AM, davel...@mac.com wrote: > >> >> I have a fetch request with sort descriptors that was sorting on a many-one >> relationship (i.e., I'm fetching Entity A which has a relationship to one >> entity B and I was trying to get back the array of A entities sorted on an >> attribute of B). This doesn't work using sort descriptors; however, if I >> apply the sort descriptor to the resulting array, it does work. > > I will assume you are using a sqlite store--otherwise these issues shouldn't > apply…
Yes, I'm using a sqlite store - the project I'm experimenting with is for iOS. >> The "if you execute a fetch directly, you should typically not add >> Objective-C-based predicates or sort descriptors to the fetch request." >> bothers me as I see lots of examples where they are used in books on Core >> Data. > > The key phrase here is "Objective-C-based." I believe the documentation is > making a distinction between the full functionality of NSPredicate and > NSSortDescriptor as executed in an Objective-C context versus the subset of > of this functionality that Core data can translate into a SQL query as > described in the doc section "Store Types and Behaviors." > >> Can someone please elaborate on what kinds of predicates and sort >> descriptors you can use when executing an NSFetchRequest using the >> NSManagedObjectContext method: executeFetchRequest:error: ? > > The docs give guidelines, and there is a little more in the Predicate > Programming Guide here: > http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Predicates/Articles/pBasics.html#//apple_ref/doc/uid/TP40001792-SW3 > but generally speaking most predicate syntax is acceptable except for any > that use any Cocoa method or Objective-C syntax, such as key paths that don't > map directly to the managed object model. > > If you find specific situations where predicates don't work that probably > should due to these guidelines you should file a radar. > > The sort descriptor issue may be how you are specifying the descriptor. It > may look at key paths differently, so you may need to experiment with > different keys (think SQL rather than KVC). That helps some - I feel more confident that my predicates will work since I'm using paths that correspond to my managed object model. Here's my sorting scenario with a few more details. Entity A (the one I'm fetching) has a to-one relation to Entity B with attribute b. Let's call the relation "tob" so my sort descriptor said withKey:@"tob.b" and it results of the fetch request did not come back in that order, but if I then sort the resulting array using the sort descriptor, it does sort it. The way I read the documentation, that should work during the fetch, but it doesn't. Thanks for the predicate link. I need to read more on those to figure out out to convert the sqlite queries I've done by hand in the past to the appropriate NSPredicate. Thanks, Dave _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com