views:

747

answers:

2

Hello,

I have a managed object model A and B with one-to-many relationship.

For this particular task, I want to retrieve all A objects which has a relation to B with a property matches to "string".

I had tried @"ALL bObjects.bProperty MATCHES 'string'", and it caused an objc_exception_throw in:

[NSSQLGenerator generateSQLStatementForFetchRequest:ignoreInheritance:countOnly:]

What seems to be the problem ?

Anybody can advise me on the correct predicate format ?

A: 

According to the Predicate Programming Guide you can't use the MATCHES operator when fetching from Core Data SQL stores.

The matches operator uses regex, so is not supported by Core Data’s SQL store— although it does work with in-memory filtering.

As for the remaining parts of your predicate, it would currently only return A objects where the entire set of bObjects has a bProperty that matches your input string.

If what you want is to return any A objects that have any object within the bObjects set that match you would want to use the ANY operator modifier.

ANY bObjects.bProperty LIKE[cd] 'string'
Ashley Clark
A: 

Thanks for pointing out that limitations, yes as much as I want to believe the documentation, I tried MATCHES for SQLite fetch request, and it does work, though for safety I changed it into LIKE.

The only thing that doesn't work is if I'm using this predicate on Core Data using SQLite storage with a fetch request on a related object (to-many in this case), not using matches.

Right now, I'm not using fetch query based on relationship, it's too risky, and I still don't know what's the mistake, I had posted this on devforums.apple.com, nobody still answer it though.