I'm getting the following error...
Invalid list of records: Cycle detected in record graph
This happens when I try to save two records with references to each other. The two record types I have are called Game and Chat. A Chat is part of a game (eventually I will have Message(s) as part of Chat which would be a one to many relationship but will tackled that another time.)
I create two CKReference objects. One for Game and one for my Chat object. I then put this into a CKModifyRecordsOperation and then get the error above. I'm uncertain what I'm missing?
Here is how I'm creating the records...
I then use the following to save the record to CloudKit...
My operation hits line 24 and outputs the error above. The only thing I can think of is that I'm creating the references incorrectly? But everything I've seen both in the documentation and online resources shows this as being correct.
Invalid list of records: Cycle detected in record graph
This happens when I try to save two records with references to each other. The two record types I have are called Game and Chat. A Chat is part of a game (eventually I will have Message(s) as part of Chat which would be a one to many relationship but will tackled that another time.)
I create two CKReference objects. One for Game and one for my Chat object. I then put this into a CKModifyRecordsOperation and then get the error above. I'm uncertain what I'm missing?
Here is how I'm creating the records...
Code Block CKRecordZoneID *zoneID = [[CKRecordZone alloc] initWithZoneName:GameZoneName].zoneID; self.record = [[CKRecord alloc] initWithRecordType:@"Game" zoneID:zoneID]; [self setCoreValues:self fromRecord:self.record]; self.record[@"name"] = self.name = theGame.name; self.chat = [[CKRecord alloc] initWithRecordType:@"Chat" zoneID:zoneID]; self.chat[@"name"] = theGame.chat.name; CKReference *gameRef = [[CKReference alloc] initWithRecordID:self.record.recordID action:CKReferenceActionNone]; self.chat[@"game"] = gameRef; [self.chat setParent:gameRef]; CKReference *chatRef = [[CKReference alloc] initWithRecordID:self.chat.recordID action:CKReferenceActionDeleteSelf]; self.record[@"chat"] = chatRef;
I then use the following to save the record to CloudKit...
Code Block CKContainer *container = [CKContainer defaultContainer]; CKDatabase *db = container.privateCloudDatabase; NSLog (@"Saving Game with name = %@", self.record[@"name"]); NSMutableArray *records = [[NSMutableArray alloc] init]; [records addObject:self.record]; [records addObject:self.chat]; NSLog(@"self.record.recordID = %@", self.record.recordID); NSLog(@"self.record[chat] = %@", self.record[@"chat"]); NSLog(@"self.chat.recordID = %@", self.chat.recordID); NSLog(@"self.chat[game] = %@", self.chat[@"game"]); CKModifyRecordsOperation *operation = [[CKModifyRecordsOperation alloc] initWithRecordsToSave:records recordIDsToDelete:nil]; operation.atomic = NO; operation.database = db; [operation setModifyRecordsCompletionBlock:^(NSArray<CKRecord *> * _Nullable savedRecords, NSArray<CKRecordID *> * _Nullable deletedRecordIDs, NSError * _Nullable operationError) { if (operationError) { failure (operationError); } else { success (savedRecords); } }]; if (self.saveQueue == nil) self.saveQueue = [[NSOperationQueue alloc] init]; [self.saveQueue addOperation:operation];
My operation hits line 24 and outputs the error above. The only thing I can think of is that I'm creating the references incorrectly? But everything I've seen both in the documentation and online resources shows this as being correct.