Nicola Montini
Nicola Montini

Reputation: 35

Core Data unimplemented SQL generation for predicate

This is the predicate:

group.AddressElements CONTAINS <AddressElement: 0x18a4b610> (entity: AddressElement; id: 0xb76dc60 <x-coredata://4F0D8450-8BB8-4361-AF55-69ED35799058/AddressElement/p2468> ; data: <fault>) 

Roughly speaking, I want to retrieve an entity that has a one to one relation with a group and the group has a to-many relation with AddressElement entity. The object I want to retrieve must have a particular AddressElement object inside the AddressElements of the related group. Therefore I wrote that predicate: group.AddressElement must contain the object I passed as parameter, which is <AddressElement: 0x18a4b610> (entity: AddressElement; id: 0xb76dc60 <x-coredata://4F0D8450-8BB8-4361-AF55-69ED35799058/AddressElement/p2468> ; data: <fault>)

When I try to fetch the request, I have a crash with unimplemented SQL generation for predicate exception.

What am I doing wrong?

Upvotes: 0

Views: 4608

Answers (1)

Dan Shelly
Dan Shelly

Reputation: 6011

As you can see here contains keyword is used for string comparison.

try modifying your predicate to (not tested):
Edit:

I have tested both:

[NSPredicate predicateWithFormat:@"ANY group.AddressElements = %@",someAddressElement]

And:

[NSPredicate predicateWithFormat:@"%@ IN manufactur.manufactures",someAddressElement]

Both resulting in the following SQL statement:

SELECT DISTINCT 0, t0.Z_PK, t0.Z_OPT, t0.ZSOMEPROP, t0.ZTOONE FROM ZSOMEENTITY t0 JOIN ZTHEONEENTITY t1 ON t0.ZTOONE = t1.Z_PK JOIN ZTHEMANY t2 ON t1.Z_PK = t2.ZTOMANY WHERE  t2.Z_PK = ?

(testing on iOS 6.1)

Upvotes: 2

Related Questions