When I log the test fetch results:

NSArray *testFetchResults = [managedObjectContext
fetchObjectsForEntityName:@"Owner" withPredicate:[NSString
stringWithFormat:@"ANY books.name like 'myPrefix*'"]];
NSLog([[(Owner *)[testFetchResults objectAtIndex:0] books]
valueForKey:@"name"]);

I get the following sample output:

----------
{(
    "foo",
    "bar",
    "myPrefix-v1",
    "myPrefix-v2"
)}
----------

yup. Your print statement, though, is not for the objects you fetched, but their related books.

These were the four test Book objects I originally associated with one
Owner, and then saved to the managed object context.

I'm unclear why the predicate statement:

@"ANY books.name like 'myPrefix*'"

would return all books, whether their name starts with 'myPrefix' or
not. The output I would expect is:

----------
{(
    "myPrefix-v1",
    "myPrefix-v2"
)}
----------

You're not fetching books, you're fetching Owner. The predicate & fetch request pair together to say:

Fetch all the Owners that have ANY (one or more) object in their books relationship with a name like 'myPrefix*'

The log statement shows the first Owner in the results array has 2 books matching your predicate. It also has a bunch of others, but that's irrelevant to whether or not it matches the predicate. You seem to be thinking of this predicate

@"ALL books.name like 'myPrefix*'"

for which we don't currently generate SQL.

- Ben



_______________________________________________

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

Reply via email to