首页 \ 问答 \ iPhone Core Data关系错误(iPhone Core Data relationship fault)

iPhone Core Data关系错误(iPhone Core Data relationship fault)

我正在构建核心数据iphone应用程序,并且无法检索一对多的关系数据。 我解释时请耐心等待。

我使用数据模型设计器来设置一个名为“Item”的实体,其中包含许多名为“Comment”的实体。 然后我检索多个实体并在UITableView显示它们。 我像这样获取这些实体(在viewDidLoad方法中):

NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Items" inManagedObjectContext:self.managedObjectContext];
[request setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(Item_to_Areas.Name LIKE %@)",[areaManagedObject valueForKey:@"Name"]];
[request setPredicate:predicate];
[request setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObject:@"Item_to_item_comments"]];
NSLog(@"Results: %@", [mutableItemsFetchResults description]);
mutableItemsFetchResults = [[managedObjectContext executeFetchRequest:request error:nil] mutableCopy];
[request release];

当用户点击一行时,我选择特定的entiny,在其init方法中将其传递给新的表视图控制器,并将新的视图控制器推送到堆栈:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"itemObject: %@", [mutableItemsFetchResults objectAtIndex:indexPath.row]);
InspectionItemCommentsViewController *itemCommentsViewController =     [[InspectionItemCommentsViewController alloc]
                                                                initWithManagedObjectContext:self.managedObjectContext 
                                                                itemObject:[mutableItemsFetchResults objectAtIndex:indexPath.row]];
itemCommentsViewController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:itemCommentsViewController animated:YES];
[itemCommentsViewController release];
}

在第一个块中,NSLog输出显示检索到“Item_to_item_comments”关系实体,但在第二个块中,即使我调用了[request setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObject:@“Item_to_item_comments”]]。

这是第一个NSLog输出的一部分:

Results: (
"<NSManagedObject: 0xb356b70> (entity: Items; id: 0xb34fe60 <x-coredata://E43A90B5-AF0E- 4394-B4A7-5EFE74E181F8/Items/p1> ; data: {\n    Clean = nil;\n    Description = \"\";\n    ItemToInformation = \"<relationship fault: 0x5e1ef00 'ItemToInformation'>\";\n    \"Item_to_Areas\" = \"0xb33fd30 <x-coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Areas/p1>\";\n    \"Item_to_item_comments\" = \"<relationship fault: 0x5e1d300 'Item_to_item_comments'>\";\n    Keys = nil;\n    Name = Other;\n    \"Tenant_agrees\" = nil;\n    Undamaged = nil;\n    Working = nil;\n})",
"<NSManagedObject: 0xb35a930> (entity: Items; id: 0xb32acc0 <x-coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Items/p2> ; data: {\n    Clean = nil;\n    Description = \"\";\n    ItemToInformation = \"<relationship fault: 0x790de40 'ItemToInformation'>\";\n    \"Item_to_Areas\" = \"0xb33fd30 <x-coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Areas/p1>\";\n    \"Item_to_item_comments\" =     (\n        \"0xb35bcb0 <x-coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Item_Comments/p13>\",\n        \"0xb35bcd0 <x-coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Item_Comments/p37>\",\n        \"0xb35bca0 <x-coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Item_Comments/p5>\",\n        \"0xb35bcc0 <x-coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Item_Comments/p26>\"\n    );\n    Keys = nil;\n    Name = Lights;\n    \"Tenant_agrees\" = nil;\n    Undamaged = nil;\n    Working = nil;\n})",

您可以看到提取了Items实体,包括Item_to_item_comments 。 这是第二个NSLog:

itemObject: <NSManagedObject: 0xe20af50> (entity: Items; id: 0xe209fc0 <x- coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Items/p2> ; data: {
    Clean = nil;
    Description = "";
    ItemToInformation = "<relationship fault: 0xe302e40 'ItemToInformation'>";
    "Item_to_Areas" = "0xe500b90 <x-coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Areas/p1>";
    "Item_to_item_comments" = "<relationship fault: 0xe302e60 'Item_to_item_comments'>";
    Keys = nil;
    Name = Lights;
    "Tenant_agrees" = nil;
    Undamaged = nil;
    Working = nil;

})

现在, Item_to_item_comments是错误的。 类似地,在推送视图控制器中,传递Items实体,但不传递Item_to_item_comments

我想我错过了一些明显的东西,但经过一天的花费在这个问题上,我无法弄清楚。

任何帮助,将不胜感激。

彼得


I am building a core data iphone app, and having trouble with retrieving one-many relationship data. Please bear with me while I explain.

I have used the data model designer to setup an entity called "Item" that contains many entities called "Comment". I then retrieve multiple entities and display them in a UITableView. I fetch these entities like this (in the viewDidLoad method):

NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Items" inManagedObjectContext:self.managedObjectContext];
[request setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(Item_to_Areas.Name LIKE %@)",[areaManagedObject valueForKey:@"Name"]];
[request setPredicate:predicate];
[request setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObject:@"Item_to_item_comments"]];
NSLog(@"Results: %@", [mutableItemsFetchResults description]);
mutableItemsFetchResults = [[managedObjectContext executeFetchRequest:request error:nil] mutableCopy];
[request release];

When the user taps on a row, I select the particular entiny, pass it to a new table view controller in its init method, and push the new view controller to the stack:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"itemObject: %@", [mutableItemsFetchResults objectAtIndex:indexPath.row]);
InspectionItemCommentsViewController *itemCommentsViewController =     [[InspectionItemCommentsViewController alloc]
                                                                initWithManagedObjectContext:self.managedObjectContext 
                                                                itemObject:[mutableItemsFetchResults objectAtIndex:indexPath.row]];
itemCommentsViewController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:itemCommentsViewController animated:YES];
[itemCommentsViewController release];
}

In the first block the NSLog output shows that the "Item_to_item_comments" relationship entities were retrieved, but in the second, that it wasn't even though I invoked [request setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObject:@"Item_to_item_comments"]].

Here is part of the first NSLog output:

Results: (
"<NSManagedObject: 0xb356b70> (entity: Items; id: 0xb34fe60 <x-coredata://E43A90B5-AF0E- 4394-B4A7-5EFE74E181F8/Items/p1> ; data: {\n    Clean = nil;\n    Description = \"\";\n    ItemToInformation = \"<relationship fault: 0x5e1ef00 'ItemToInformation'>\";\n    \"Item_to_Areas\" = \"0xb33fd30 <x-coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Areas/p1>\";\n    \"Item_to_item_comments\" = \"<relationship fault: 0x5e1d300 'Item_to_item_comments'>\";\n    Keys = nil;\n    Name = Other;\n    \"Tenant_agrees\" = nil;\n    Undamaged = nil;\n    Working = nil;\n})",
"<NSManagedObject: 0xb35a930> (entity: Items; id: 0xb32acc0 <x-coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Items/p2> ; data: {\n    Clean = nil;\n    Description = \"\";\n    ItemToInformation = \"<relationship fault: 0x790de40 'ItemToInformation'>\";\n    \"Item_to_Areas\" = \"0xb33fd30 <x-coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Areas/p1>\";\n    \"Item_to_item_comments\" =     (\n        \"0xb35bcb0 <x-coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Item_Comments/p13>\",\n        \"0xb35bcd0 <x-coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Item_Comments/p37>\",\n        \"0xb35bca0 <x-coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Item_Comments/p5>\",\n        \"0xb35bcc0 <x-coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Item_Comments/p26>\"\n    );\n    Keys = nil;\n    Name = Lights;\n    \"Tenant_agrees\" = nil;\n    Undamaged = nil;\n    Working = nil;\n})",

You can see that the Items entities are fetched, including Item_to_item_comments. Here's the second NSLog:

itemObject: <NSManagedObject: 0xe20af50> (entity: Items; id: 0xe209fc0 <x- coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Items/p2> ; data: {
    Clean = nil;
    Description = "";
    ItemToInformation = "<relationship fault: 0xe302e40 'ItemToInformation'>";
    "Item_to_Areas" = "0xe500b90 <x-coredata://E43A90B5-AF0E-4394-B4A7-5EFE74E181F8/Areas/p1>";
    "Item_to_item_comments" = "<relationship fault: 0xe302e60 'Item_to_item_comments'>";
    Keys = nil;
    Name = Lights;
    "Tenant_agrees" = nil;
    Undamaged = nil;
    Working = nil;

})

Now, Item_to_item_comments is fault. Similarly, in the pushed view controller, the Items entity is passed, but Item_to_item_comments is not.

I think I am missing something obvious, but after a day spend on this problem, I can't figure it out.

Any help would be appreciated.

Peter


原文:https://stackoverflow.com/questions/3123950
更新时间:2023-10-02 20:10

最满意答案

在IPython中,你可以调用%paste它将剪贴板粘贴到终端中。

注:据我所知,你应该安装tkinter使用%paste


The %paste command works, but what I was actually looking for was %doctest_mode. More cool hacks can be found here

相关问答

更多
  • 在我的情况下,这是一个LaTex库需要安装(对不起,我没有注意哪一个) 它会自动打开我的MikTex安装程序,所以你安装了建议的库,你应该完成。 不需要从命令行访问'lp'。 In my case it was a LaTex library that needed to be installed (sorry I didn't pay attention to which one) It automatically opened my MikTex installer, so you install th ...
  • 您不能直接复制到IPython。 这是步骤: 将要复制到IPython的行复制到剪贴板中 输入%paste到IPython 按回车 利润! You can't copy to IPython directly. This are the steps: Copy the lines you want to copy into IPython into the clipboard Enter %paste into IPython Press enter Profit!
  • 为方便起见,如果在提示符下键入表达式,则将打印表达式的值。 但是如果你只是在python文件中编写相同的表达式,它将被评估,但不会打印该值。 如果要从正在运行的文件中print x的值,则应print x 。 As a convenience, if you type an expression at the prompt, the value of the expression will be printed. But if you just write the same expression in a ...
  • ipython是一种改进的交互式提示符,而不是库。 它具有标签完成和配置文件等功能,它们不存在于vanilla交互式提示符(运行python而没有输入文件)中。 所有功能都列在您引用的页面上。 所以,它并不能真正改善你的日常Python应用程序体验(不管这意味着什么),但它确实在开发过程中提供了好处。 此外,还有一种称为bpython的替代方案,它也具有相当好的功能。 ipython is an improved interactive prompt, not a library. It has featu ...
  • 只有在使用-wthread调用-wthread时才会发生这种情况,我刚刚提交了一个关于此的错误 。 This happens only when ipython is called with -wthread, I've just filed a bug about this.
  • 这在ipython 5.3中ipython 5.3 。 从(破碎的)ipython 4.X升级: pip install -U ipython 然后一切都是kopacetic。 This is fixed in ipython 5.3 . To upgrade from the (broken) ipython 4.X: pip install -U ipython Then everything's kopacetic.
  • 在IPython中,你可以调用%paste它将剪贴板粘贴到终端中。 注:据我所知,你应该安装tkinter使用%paste 。 The %paste command works, but what I was actually looking for was %doctest_mode. More cool hacks can be found here
  • 此服务器错误应该在周末解决。 为麻烦道歉。 This server error should have been resolved over the weekend. Apologies for the trouble.
  • 运行脚本train.py的python进程和你在ipython命令行中使用的python进程是两个独立的进程。 有意义的是,一个人不知道另一个的变量。 可能有一些奇特的方式来连接这两个,但我怀疑你描述问题的方式,这是不值得的工作。 这是一种更简单的访问方式:您可以使用python -i train.py替换脚本中的python -i train.py 。 这样,您将在完成后运行脚本的过程中进入交互模式,并且可以访问主级别定义的任何内容。 您可以在脚本中插入对pdb.set_trace()的调用以停止在任意点 ...
  • 在IPython Notebook中,在带有bang(“!”)的shell命令之前将对大多数命令起作用(例如,“!date”),但是,如上所述,多行命令未正确传递。 根据IPython中的细胞魔法 IPython具有%%script单元魔法,它允许您在系统上的任何解释器的子进程中运行单元格,例如:bash,ruby,perl,zsh,R等。 它甚至可以是您自己的脚本,它希望在stdin上输入。 要使用它,只需将path或shell命令传递给要在%%script行上运行的程序,该%%script的其余部分将由 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。