Soo*_*uNe 23 core-data cascading-deletes
这个问题可能是一个长镜头.在删除实体后保存时,我无法弄清楚我在核心数据项目中遇到的错误.我的.xcdatamodel可以在:
我有两个与我合作的主要实体,一件衣服和一件物品.我可以毫无问题地创建它们但是当我删除它们时,我得到以下错误日志:
为装备:
2009-09-22 20:17:37.771 itryiton[29027:20b] Operation could not be completed. (Cocoa error 1600.)
2009-09-22 20:17:37.773 itryiton[29027:20b] {
NSLocalizedDescription = "Operation could not be completed. (Cocoa error 1600.)";
NSValidationErrorKey = outfitArticleViewProperties;
NSValidationErrorObject = <Article: 0x12aa3c0> (entity: Article; id: 0x12b49a0 <x-coredata://7046DA47-FCE1-4E21-8D7B-E532AAC0CC46/Article/p1> ; data: {
articleID = 2009-09-22 19:05:19 -0400;
articleImage = 0x12b4de0 <x-coredata://7046DA47-FCE1-4E21-8D7B-E532AAC0CC46/ArticleImage/p1>;
articleType = nil;
attributeTitles = "(...not nil..)";
color = nil;
comment = nil;
dateCreated = 2009-09-22 19:05:19 -0400;
designer = nil;
imageView = "(...not nil..)";
location = "(...not nil..)";
outfitArticleViewProperties = (
0x12b50f0 <x-coredata://7046DA47-FCE1-4E21-8D7B-E532AAC0CC46/OutfitArticleViewProperties/p1>
);
ownesOrWants = 0;
pattern = nil;
price = nil;
retailer = nil;
thumbnail = "(...not nil..)";
washRequirements = nil;
wearableSeasons = nil;
});
NSValidationErrorValue = {(
<OutfitArticleViewProperties: 0x1215340> (entity: OutfitArticleViewProperties; id: 0x12b50f0 <x-coredata://7046DA47-FCE1-4E21-8D7B-E532AAC0CC46/OutfitArticleViewProperties/p1> ; data: {
article = 0x12b49a0 <x-coredata://7046DA47-FCE1-4E21-8D7B-E532AAC0CC46/Article/p1>;
articleViewPropertiesID = nil;
outfit = nil;
touch = nil;
view = "(...not nil..)";
})
)};
}
Run Code Online (Sandbox Code Playgroud)
如果我删除了我得到的文章:
2009-09-22 18:58:38.591 itryiton[28655:20b] Operation could not be completed. (Cocoa error 1560.)
2009-09-22 18:58:38.593 itryiton[28655:20b] DetailedError: {
NSLocalizedDescription = "Operation could not be completed. (Cocoa error 1600.)";
NSValidationErrorKey = articleImage;
NSValidationErrorObject = <Article: 0x12aa340> (entity: Article; id: 0x12b3f10 <x-coredata://05340FA6-B5DC-4646-A5B4-745C828C73C3/Article/p1> ; data: {
articleID = 2009-09-22 18:58:26 -0400;
articleImage = 0x12b4d00 <x-coredata://05340FA6-B5DC-4646-A5B4-745C828C73C3/ArticleImage/p1>;
articleType = nil;
attributeTitles = "(...not nil..)";
color = nil;
comment = nil;
dateCreated = 2009-09-22 18:58:26 -0400;
designer = nil;
imageView = "(...not nil..)";
location = "(...not nil..)";
outfitArticleViewProperties = (
0x12b5010 <x-coredata://05340FA6-B5DC-4646-A5B4-745C828C73C3/OutfitArticleViewProperties/p1>
);
ownesOrWants = 0;
pattern = nil;
price = nil;
retailer = nil;
thumbnail = "(...not nil..)";
washRequirements = nil;
wearableSeasons = nil;
});
NSValidationErrorValue = <ArticleImage: 0x12ad600> (entity: ArticleImage; id: 0x12b4d00 <x-coredata://05340FA6-B5DC-4646-A5B4-745C828C73C3/ArticleImage/p1> ; data: {
article = 0x12b3f10 <x-coredata://05340FA6-B5DC-4646-A5B4-745C828C73C3/Article/p1>;
image = "(...not nil..)";
});
}
Run Code Online (Sandbox Code Playgroud)
1600错误是:
NSValidationRelationshipDeniedDeleteError用于表示与删除规则的某些关系的错误代码NSDeleteRuleDeny非空.
适用于Mac OS X v10.4及更高版本.
在CoreDataErrors.h中声明.
但我无法看到我的生活中哪种关系会妨碍删除.如果某些Core Data向导可以看到我的方式错误,我会感到谦卑.但是说真的,谢谢!
我的型号图片: 替代文字http://img121.yfrog.com/img121/4413/picture11.png
最终更新:我无法将此标记解决,因为我没有真正解决它,但我确实有一个解决方案.在我的每个托管对象的.m中,我添加了一个方法,如下所示:
-(void) deleteFromManangedObjectContext{
self.outfit = nil;
self.article = nil;
[[self managedObjectContext] deleteObject:self];
}
Run Code Online (Sandbox Code Playgroud)
所以你可以看到,首先我手动清除关系,然后我自己删除对象.在其他对象中,不是nil-ing,而是在一些对象关系上调用我的delete方法,以获得级联.
我仍然对"正确"的答案感兴趣.但这是我拥有的最佳解决方案,它确实可以对我的关系的删除方式进行细致的控制.
我刚刚遇到删除失败的问题,并着手解决这个问题.我已经弄清楚了我的问题,并认为我也会分享这个问题,也许有人会遇到同样的问题.
我犯的错误是我试图删除的对象(A)与另一个对象(B)的关系,其中NULL为删除规则.但是,对象B也与A有关系,而且它是非可选的.因此,当我删除A时,B的A关系变为空,这是不允许的.当我将删除规则更改为级联并且它工作时.
我无法将此标记为已解决,因为我没有真正解决它,但我确实有一个可行的解决方法。在每个 ManagedObjects 的 .m 中,我添加了一个如下所示的方法:
-(void) deleteFromManangedObjectContext{
self.outfit = nil;
self.article = nil;
[[self managedObjectContext] deleteObject:self];
}
Run Code Online (Sandbox Code Playgroud)
所以你可以看到,首先我手动删除关系,然后我让对象自行删除。在其他对象中,我的删除方法不是在某些对象关系上调用,而是调用,以获得级联。
我仍然对“正确”答案感兴趣。但这是我拥有的最佳解决方案,它确实允许对删除关系的方式进行一些细粒度的控制。
| 归档时间: |
|
| 查看次数: |
9091 次 |
| 最近记录: |