2014-04-15 107 views
0

我的結構具有實體'wall post',它具有相同的結構化實體'repost'。他們有關係('牆柱'與'目的地'重新發布''作爲'牆柱',反轉爲'轉貼')。CoreData(MagicalRecord)獲取已保存的對象

與代碼

 NSArray *newsEntities = [[NSArray alloc] init]; 
    newsEntities = [WallpostEntity findAllSortedBy:@"pubDate" ascending:NO]; 

現在我得到的對象我有WallpostEntity和轉播的陣列。我怎樣才能得到'牆上的帖子'?

回答

0

我可以想到,在這個獲取請求中獲得兩種不同類型的實體的唯一方法是,您已將WallPost實體建模爲Repost的基類。也就是說,Repost是Wallpost的一個子類。如果您只希望Wallposts從您的請求中返回,那麼您需要像這樣修改代碼:

NSFetchRequest *request = [WallpostEntity MR_requestAllSortedBy:@"pubDate" ascending:NO]; 
[request setIncludesSubEntities:NO]; 
newsEntities = [WallpostEntity MR_executeRequest:request]; 
相關問題