2014-05-20 21 views
0

在我的核心數據模型中,我有會話類,它具有「參與者」關係,其中的元素是Participant類的實例。參與者類有一個字符串的href字段。與包含一對多關係的核心數據謂詞

使用MagicalRecord,我試圖獲取所有具有至少一個參與者的實例,該實例的href包含'/ businesses /%@',其中%@是給定的標識符。在商業術語中,這意味着加載具有給定標識符的企業是參與者的所有對話。

這是應該做的抓取代碼:

NSPredicate *participationFilter = [NSPredicate predicateWithFormat:@"ANY participants.href contains[cd] '/businesses/%@'" argumentArray:@[identifier]]; 
NSArray *conversations = [Conversation MR_findAllWithPredicate:participationFilter]; 

但談話總是空的,即使我知道,這樣的對話是在我的數據庫。我究竟做錯了什麼?

+0

使用魔法記錄有什麼意義? –

+0

魔法記錄是一個開源框架,使Core Data更容易操作:https://github.com/magicalpanda/MagicalRecord – Sebastien

+0

哦,一個核心數據包裝....不是我的特長x.x –

回答

0

'...'在謂詞中被視爲文字字符串,並且 引號內的%@佔位符未被展開。你必須先建立組合字符串:

NSString *searchTerm = [NSString stringWithFormat:@"/businesses/%@", identifier]; 
NSPredicate *participationFilter = [NSPredicate predicateWithFormat:@"ANY participants.href contains[cd] %@", searchTerm]; 
+0

完美。感謝它現在的作品。 – Sebastien