【问题标题】:NSPredicate with relationship @"SELF.<relationship>.<relationship>.<object> == %@"NSPredicate 与关系 @"SELF.<relationship>.<relationship>.<object> == %@"
【发布时间】:2012-10-20 22:32:08
【问题描述】:

我有以下NSManagedObjects

Product <<->> ProductAttribute <->> ProductAttributeOption

使用 NSPredicate 获取基于产品的ProductAttributeOptions 的正确方法是什么?

我尝试了以下方法,但没有运气:

[NSPredicate predicateWithFormat:@"ANY SELF.productAttribute.products MATCHES %@", product]

[NSPredicate predicateWithFormat:@"ANY SELF.productAttribute@distinctUnionOfSets.products MATCHES %@"", product]

[NSPredicate predicateWithFormat:@"ANY SELF.productAttribute.@distinctUnionOfSets.giftProducts LIKE[cd] %@", self.giftProduct]

有什么建议吗?谢谢!

【问题讨论】:

    标签: core-data nspredicate relationship nsmanagedobject nsfetchedresultscontroller


    【解决方案1】:

    以下谓词应该有效:

    [NSPredicate predicateWithFormat:@"ANY productAttribute.products = %@", product];
    

    “MATCH”和“LIKE”用于匹配字符串的谓词。

    【讨论】:

    • 快到了,我最终得到了[NSPredicate predicateWithFormat:@"ANY SELF.productAttribute.products = %@", product] 但它让我走上了正确的道路:) 谢谢!
    • @runmad:我原以为这两个版本(有或没有SELF)都可以处理获取请求。但无论如何,我很高兴它有所帮助。
    猜你喜欢
    • 1970-01-01
    • 2022-01-03
    • 2020-11-11
    • 2014-03-07
    • 2020-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-17
    相关资源
    最近更新 更多