iOSProgrammingIsFun
iOSProgrammingIsFun

Reputation: 1458

iOS - NSPredicate One-to-Many Core Data

I have two entities: Dictionary and DictionaryItems

A 'Dictionary' has a one to many relationship called 'terms' to the 'DictionaryItems' Entity

i.e. Dictionary = English DictionaryItems = Cabbage, Babble, Green, Bus

I have two tables, the first shows a list of my Dictionary objects i.e.:

English Spanish Klingon

After touching one of those, it pushes on a new table that should show all of the items contained in that dictionary.

However my NSPredicate seems to be the problem as nothing is showing in that 2nd Table.

I've used a Mac app that interrogates the SQL database backend and I can confirm all the entries are there, and the relationship seems to be wired up correctly... however nothing is returned and it seems to be the NSPredicate's fault.

This is what I have:

NSEntityDescription * entity = [NSEntityDescription entityForName:@"DictionaryItems" inManagedObjectContext:self.managedObjectContext];

NSPredicate * predicate = [NSPredicate predicateWithFormat:@"dictionary == %@", self.myDictionaryManagedObject];

[fetchRequest setPredicate:predicate];

Where 'self.myDictionaryObject' is a property containing the 'Dictionary' Managed Object chosen from the first table. This object is valid and correct.

Upvotes: 0

Views: 329

Answers (2)

iOSProgrammingIsFun
iOSProgrammingIsFun

Reputation: 1458

Here's the fix:

NSPredicate * predicate = [NSPredicate predicateWithFormat:@"ANY SELF.dictionary = %@", self.myDictionaryObject];

Knew it was the predicate!!

Upvotes: 1

Jonathan Arbogast
Jonathan Arbogast

Reputation: 9650

In your question you say that those entities are DictionaryTerms. However, you are creating an NSEntityDescription with the name DictionaryItems.

Upvotes: 0

Related Questions