iPhone CoreData join

后端 未结 2 1176
礼貌的吻别
礼貌的吻别 2020-12-18 12:52

this is my core data model:

\"enter

I\'m trying to get all LanguageEntries fro

相关标签:
2条回答
  • 2020-12-18 13:25

    The predicate properly wasn't created correctly, you must pass the parameters to predicateWithFormat. It should have been:

    fetchRequest.predicate = [NSPredicate predicateWithFormat:@"Category.categoryName = %@ AND LanguageSet.languageSetName = %@", 
                                                              @"Food", 
                                                              @"English####Spanish"];
    

    In case you were wondering what that does is it puts quotes around the string parameters automatically which are required when using a string in a predicate. When you created the query using NSString's format method that did not put the required quotes in.

    0 讨论(0)
  • 2020-12-18 13:34

    Your can't think of Core Data as SQL. There is no such thing as a "join" in Core Data. In this case, your trying to find the intersection of two sets of objects. Close to a join logically but not in the implementation details. And the programming devil is always in the details.

    Try using the logical equal "==" like so:

    @"Category.categoryName == %@ AND LanguageSet.languageSetName == %@"
    

    I believe that will solve your problem.

    The data model has a predicate editor hidden way in it. It can help you set up predicates even if you don't embed them in fetches in model itself. Just select an entity, in your case "LanguageEntity", then add a Fetch Request. The edit predicate will appear and you can use the dialog to create the predicate. It will display a textual version of the predicate that you can copy into your code.

    0 讨论(0)
提交回复
热议问题