Core Data Predicates with Relationships and Objects
Core Data Predicates with Relationships and Objects
- Subject: Core Data Predicates with Relationships and Objects
- From: Adam Ernst <email@hidden>
- Date: Sat, 5 Nov 2005 18:52:45 -0600
If I have a Core Data model that has a one-to-many relationship, like
this:
[Customer] <--------->>> [Order]
And I have a reference to a customer:
NSManagedObject *myCustomer;
How can I get the most recent order for that customer using a Core
Data predicate? (Order has a "date" property.) Since I can't find a
"greatest" specifier, I'm going to try to retrieve all the orders for
a given customer.
So how do I do that? I don't want to use "customer.name LIKE %@",
[myCustomer valueForKey: name] since that's fuzzy; multiple customers
might have the same name. I've tried dropping the object in directly:
[NSPredicate predicateWithFormat:@"(customer==%@)", myCustomer];
("customer" is the name of the relationship that connects the order
to its parent customer. myCustomer is a NSManagedObject ptr, as shown
above.)
But that doesn't seem to work either. It fails to match any rows at
all. (See the sample CoreRecipesApp,
RecipeUtilities.m:recipeForApplicationURL for this syntax, where it
apparently works.)
Suggestions?
Adam Ernst
cosmicsoft
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden