- 視頻
- 播放列表項
- 播放列表
關係:
- 視頻是可選的一對多播放列表項目和刪除規則無效
- 播放列表是一對多的至少一個播放列表項和刪除規則是抵消
- 播放列表項要求,一個用於視頻和刪除規則被廢除
- 播放列表項要求 - 一個用於播放列表並且刪除規則爲無效
在播放列表實體中,我沒有公開playlistItem關係/ set。相反,我有一個名爲「視頻」的短暫未定義屬性,它是通過對播放列表項進行排序而生成的視頻實體數組。播放列表和視頻實體之間沒有關係。
我在將管理對象上下文中保存修改的播放列表實例時遇到了問題。
從playlist.m(NSManagedObject子類):
- (BOOL)validatePlaylistItems:(NSSet **)playlistItems error:(NSError **)outError
{
NSArray *currentVideos = [self videos];
NSArray *persistedVideos = [self videosFromPlaylistItems];
if ([currentVideos isEqual:persistedVideos]) {
return YES;
}
NSManagedObjectContext *context = [self managedObjectContext];
for (FHPlaylistItem *pi in *playlistItems) {
[context deleteObject:pi];
}
NSArray *videos = [self primitiveVideos];
NSUInteger count = [videos count];
for (int i = 0; i < count; i++) {
FHPlaylistItem *pi = [FHPlaylistItem playlistItemWithVideo:[videos objectAtIndex:i]
forIndex:i
insertIntoManagedObjectContext:[self managedObjectContext]];
[self addPlaylistItemsObject:pi];
[pi setPlaylist:self];
}
return YES;
}
我想在這裏完成只更新播放列表項時,MOC需要保存,正如你所看到的操作昂貴 - O(N * 2)。在應用程序的第一次運行期間,MOC保存得很好。但是,後續對視頻屬性的更改會在Core Data中產生一堆錯誤:
Core Data: annotation: repairing missing delete propagation for to-many relationship playlistItems on object <FHPlaylist: 0x6c27eb0> (entity: Playlist; id: 0x6c26d40 <x-coredata://BCB69D8E-8393-4A2A-AF5D-0AA1872CE2B4/Playlist/p19> ; data: {
accountID = 0;
lastFetched = "2012-03-31 20:05:08 +0000";
name = Featured;
playlistID = 1441335931001;
playlistItems = (
"0x6c34be0 <x-coredata:///PlaylistItem/t9EAFBC87-5E16-4053-984F-881CCD9C1F0B2>",
"0x6c34320 <x-coredata://BCB69D8E-8393-4A2A-AF5D-0AA1872CE2B4/PlaylistItem/p16>",
"0x6c310c0 <x-coredata:///PlaylistItem/t9EAFBC87-5E16-4053-984F-881CCD9C1F0B3>",
"0x6c35570 <x-coredata:///PlaylistItem/t9EAFBC87-5E16-4053-984F-881CCD9C1F0B5>",
"0x6c34ca0 <x-coredata:///PlaylistItem/t9EAFBC87-5E16-4053-984F-881CCD9C1F0B6>",
"0x6c34310 <x-coredata://BCB69D8E-8393-4A2A-AF5D-0AA1872CE2B4/PlaylistItem/p8>",
"0x6c28a90 <x-coredata:///PlaylistItem/t9EAFBC87-5E16-4053-984F-881CCD9C1F0B4>",
"0x6c34350 <x-coredata://BCB69D8E-8393-4A2A-AF5D-0AA1872CE2B4/PlaylistItem/p29>",
"0x6c34220 <x-coredata://BCB69D8E-8393-4A2A-AF5D-0AA1872CE2B4/PlaylistItem/p2>",
"0x6c34330 <x-coredata://BCB69D8E-8393-4A2A-AF5D-0AA1872CE2B4/PlaylistItem/p20>",
"(...and 1 more...)"
);
playlistType = 0;
referenceID = OKFFeaturedPlaylist;
shortDescrip = "This is so descriptive! OMG!";
thumbnailURL = nil;
videos = "(...not nil..)";
}) with bad fault 0x6c34320 <x-coredata://BCB69D8E-8393-4A2A-AF5D-0AA1872CE2B4/PlaylistItem/p16>
Core Data: annotation: repairing missing delete propagation for to-many relationship playlistItems on object <FHPlaylist: 0x6c27eb0> (entity: Playlist; id: 0x6c26d40 <x-coredata://BCB69D8E-8393-4A2A-AF5D-0AA1872CE2B4/Playlist/p19> ; data: {
accountID = 0;
lastFetched = "2012-03-31 20:05:08 +0000";
name = Featured;
playlistID = 1441335931001;
playlistItems = (
"0x6c34be0 <x-coredata:///PlaylistItem/t9EAFBC87-5E16-4053-984F-881CCD9C1F0B2>",
"0x6c310c0 <x-coredata:///PlaylistItem/t9EAFBC87-5E16-4053-984F-881CCD9C1F0B3>",
"0x6c35570 <x-coredata:///PlaylistItem/t9EAFBC87-5E16-4053-984F-881CCD9C1F0B5>",
"0x6c34ca0 <x-coredata:///PlaylistItem/t9EAFBC87-5E16-4053-984F-881CCD9C1F0B6>",
"0x6c34310 <x-coredata://BCB69D8E-8393-4A2A-AF5D-0AA1872CE2B4/PlaylistItem/p8>",
"0x6c28a90 <x-coredata:///PlaylistItem/t9EAFBC87-5E16-4053-984F-881CCD9C1F0B4>",
"0x6c34350 <x-coredata://BCB69D8E-8393-4A2A-AF5D-0AA1872CE2B4/PlaylistItem/p29>",
"0x6c34220 <x-coredata://BCB69D8E-8393-4A2A-AF5D-0AA1872CE2B4/PlaylistItem/p2>",
"0x6c34330 <x-coredata://BCB69D8E-8393-4A2A-AF5D-0AA1872CE2B4/PlaylistItem/p20>",
"0x6c34340 <x-coredata://BCB69D8E-8393-4A2A-AF5D-0AA1872CE2B4/PlaylistItem/p27>"
);
playlistType = 0;
referenceID = OKFFeaturedPlaylist;
shortDescrip = "This is so descriptive! OMG!";
thumbnailURL = nil;
videos = "(...not nil..)";
}) with bad fault 0x6c34310 <x-coredata://BCB69D8E-8393-4A2A-AF5D-0AA1872CE2B4/PlaylistItem/p8>
Etc. Etc. Etc.
看起來問題在於刪除規則。抱怨與「缺失刪除傳播」,所以它似乎無效是錯誤的選擇。但是,爲什麼它錯了?這對我沒有意義。如果我將播放列表項目的刪除規則設置爲級聯,Apple's Core Data Programming Guide中級聯刪除規則的措辭使我看起來像刪除視頻和播放列表對象。
瀑布 - 在關係的目標刪除的對象
此外,如果我在快速列舉迴路設置播放列表中的項目的關係,視頻&播放列表爲零,核心數據沒有按」 t抱怨不得不修復缺失的刪除傳播。
for (FHPlaylistItem *pi in *playlistItems) {
[pi setVideo:nil];
[pi setPlaylist:nil];
[context deleteObject:pi];
}
編輯:不,手動nil'ing的關係並不適用於所有情況。 (也許不奇怪?)
同樣的問題,我也面臨着。但是,增加上述方法沒有變化之後,仍然保持發出相同:https://stackoverflow.com/questions/49129364/core-data-after-adding-unique-constraint-annotation-repairing-missing-delet – Nagarajan 2018-03-08 04:55:16