1
如果我有父母子女孫子的實體,以及他們之間的一對多關係,我知道我可以爲父母或所有孫子實體獲得所有子實體。iPhone核心數據得到孫子們
是否可以運行一個將獲取給定Parent的所有Granchild實體的提取?
感謝您的幫助!
如果我有父母子女孫子的實體,以及他們之間的一對多關係,我知道我可以爲父母或所有孫子實體獲得所有子實體。iPhone核心數據得到孫子們
是否可以運行一個將獲取給定Parent的所有Granchild實體的提取?
感謝您的幫助!
對於每個對多關係都沒有反向關係,否則不能運行您描述的獲取請求。然而,你應該建模逆關係。 CoreData使用反轉來維護對象圖的一致性。鑑於從Child
到Parent
和Grandchind
parent
關係,Child
,你可以做
Pareint *aParent; //already initialized
NSSet *allGrandchildren = [aParent valueForKeyPath:@"[email protected]"];
或謂語的Grandchild
實體爲獲取請求:
[NSPredicate predicateWithFormat:@"parent.parent == %@", aParent];
感謝您的! – Fogmeister 2010-08-22 16:22:44