• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Core Data Predicates with Relationships and Objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Core Data Predicates with Relationships and Objects
      • From: mmalcolm crawford <email@hidden>
  • Prev by Date: Strange behaviour of scanFloat
  • Next by Date: NSTask and unicode arguments
  • Previous by thread: Re: Strange behaviour of scanFloat
  • Next by thread: Re: Core Data Predicates with Relationships and Objects
  • Index(es):
    • Date
    • Thread