简体   繁体   English

核心数据关系未保存到商店

[英]Core Data relationship not saved to store

I've got this command line app that iterates through CSV files to create a Core Data SQLite store. 我有这个命令行应用程序,它遍历CSV文件以创建Core Data SQLite存储。 At some point I'm building these SPStop objects, which has routes and schedules to-many relationships: 在某些时候,我正在构建这些SPStop对象,它具有routesschedules到多个关系:

SPRoute *route = (SPRoute*)[self.idTransformer objectForOldID:routeID ofType:@"routes" onContext:self.coreDataController.managedObjectContext];

SPStop *stopObject = (SPStop*)[self.idTransformer objectForOldID:stopID ofType:@"stops" onContext:self.coreDataController.managedObjectContext];
[stopObject addSchedulesObject:scheduleObject];
[stopObject addRoutesObject:route];

[self.coreDataController saveMOC];

If I log my stopObject object (before or after saving; same result), I get the following: 如果我记录我的stopObject对象(在保存之前或之后;相同的结果),我得到以下内容:

latitude = "45.50909";
longitude = "-73.80914";
name = "Roxboro-Pierrefonds";
routes =     (
    "0x10480b1b0 <x-coredata://A7B68C47-3F73-4B7E-9971-2B2CC42DB56E/SPRoute/p2>"
);
schedules =     (
    "0x104833c60 <x-coredata:///SPSchedule/tB5BCE5DC-1B08-4D11-BCBB-82CD9AC42AFF131>"
);

Notice how the routes and schedules object URL formats differ? 请注意路由和计划对象URL格式有何不同? This must be for a reason, because further down the road when I use the sqlite store and print the same stopObject , my routes set is empty, but the schedules one isn't. 这必须是有原因的,因为当我使用sqlite存储并打印相同的stopObject ,我的routes设置为空,但是schedules不是。

I realize this is very little debugging information but maybe the different URL formats rings a bell for someone? 我意识到这是很少的调试信息,但也许不同的URL格式为某人敲响了警钟? What could I be doing wrong that would cause this? 我可能做错了会导致这种情况吗?

EDIT : it seems that one SPRoute object can only be assigned to one SPStop at once. 编辑 :似乎一个SPRoute对象只能一次分配给一个SPStop。 I inserted breakpoints at the end of the iteration and had a look a the sqlite every time and I definitely see that as soon as an SPRoute object (that already had been assigned to a previous stop.routes ) is assigned to a new SPStop, the previous stop.routes set gets emptied. 我在迭代结束时插入断点并且每次都看一下sqlite,我确实看到一旦SPRoute对象(已经分配给前一个stop.routes )被分配给一个新的SPStop,之前的stop.routes设置被清空。 How can this be? 怎么会这样?

Well, we had disabled Xcode's inverse relationship's warning which clearly states: 好吧,我们禁用了Xcode的反向关系警告,该警告明确指出:

SPStop.routes does not have an inverse; SPStop.routes没有反转; this is an advanced setting (no object can be in multiple destinations for a specific relationship) 这是一个高级设置(没有对象可以在特定关系的多个目标中)

Which was precisely our issue. 这正是我们的问题。 We had ditched inverse relationships because Apple states that they're only good for "data integrity". 我们抛弃了反向关系,因为Apple声称它们只对“数据完整性”有利。 Our store is read-only so we figured we didn't really need them. 我们的商店是只读的,所以我们认为我们并不真正需要它们。 We learn now that inverse relationships are a little more than just for "data integrity" :P 我们现在知道,反向关系不仅仅是“数据完整性”:P

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM