【问题标题】:CoreData(MagicalRecord) getting saved objectsCoreData(MagicalRecord) 获取保存的对象
【发布时间】:2014-04-15 09:02:20
【问题描述】:

我有实体“墙帖”的结构,它具有相同的结构化实体“转发”。他们有关系(“墙帖”有“转贴”,目的地为“墙帖”,反之为“转帖”)。

现在我正在使用代码获取对象

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

我有 WallpostEntity 并在数组中转发。我怎样才能只获得“墙帖”?

【问题讨论】:

    标签: ios database core-data magicalrecord


    【解决方案1】:

    我能想到的唯一方法是,您在此获取请求中获得了两种不同类型的实体,即您已将 WallPost 实体建模为 Repost 的基类。也就是说,Repost 是 Wallpost 的子类。如果您只想从您的请求中返回 Wallposts,那么您需要修改您的代码,如下所示:

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

    【讨论】:

      猜你喜欢
      • 2014-09-12
      • 1970-01-01
      • 1970-01-01
      • 2011-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多