Swift 4 - Problem forming 1:n relation

Hi,
I’m trying to form a 1:n relation between a Director and his/her Movies. I can get the 1:n relation to work (1 Director, multiple movies), but I can’t form the reverse. I get an error saying
FAULT = ‘1303’ [Unable to create relation. Child object with id ‘’ is not found in the related table.] <Unable to create relation. Child object with id ‘’ is not found in the related table.>
FAULT = ‘1303’ [Unable to create relation. Child object with id ‘’ is not found in the related table.] <Unable to create relation. Child object with id ‘’ is not found in the related table.>

This happens twice, once per reverse relation.
The Director and Movies all seem to have legitimate objectIds (although the ownerIds are blank) – the error doesn’t say which of the two it means.
I trie attaching a file, but that doesn’t seem to have worked, so I will paste the code in here. Any help would be greatly appreciated!! I’m hoping to use this in my class, but needless to say I need to get it to work, first! It would be great if there was a full-blown, Swift 4 example (even with something as simple as what I’ve shown here) to help novices such as yours truly.
func relating(){


 
 let director0 = Director(name: "Alfred Hitchcock")
 let movie0 = Movie(title: "The Birds", year: 1960)
 let movie1 = Movie(title: "Vertigo", year: 1961)
 
 let savedDirector = dataStoreDirector?.save(director0) as! Director
 let savedMovie0 = dataStoreMovie?.save(movie0) as! Movie
 let savedMovie1 = dataStoreMovie?.save(movie1) as! Movie
 let movies = [savedMovie0.objectId, savedMovie1.objectId] as! [String]
 
 print(savedDirector.objectId ?? "0")
 print(savedMovie0.objectId ?? "1")
 print(savedMovie1.objectId ?? "2")
 
 // for 1:1 relations, use the ":1" notation instead of ":n"
 
 let _ = dataStoreDirector?.addRelation("movies:Movie:n", //
 parentObjectId: savedDirector.objectId,
 childObjects: movies,
 response:{(num:NSNumber?)->Void in print("Adding movies -- \(String(describing: num))")},
 error:{(faulter)->Void in print(faulter ?? "Error in - adding movies")})
 
 let _ = dataStoreMovie?.setRelation("director:Director:1", //
 parentObjectId:savedMovie0.objectId,
 childObjects:[savedDirector],
 response:{(num:NSNumber?)->Void in print("Adding director to first movie -- \(String(describing: num))")},
 error:{(faulter)->Void in print(faulter ?? "eh, what's up, Doc - adding director to first movie")})
 
 let _ = dataStoreMovie?.setRelation("director:Director:1", //
 parentObjectId:savedMovie1.objectId,
 childObjects:[savedDirector],
 response:{(num:NSNumber?)->Void in print("Adding director to first movie -- \(String(describing: num))")},
 error:{(faulter)->Void in print(faulter ?? "eh, what's up, Doc")})
 
 }

Hello,

I’ve forwarded the the problem to our iOS team. We’ll investigate the behavior and report back ASAP. Ticket id is:
BKNDLSS-15945

Best Regards

Thanks, Anton - if you need my entire codebase, with the definition of the Director and Movie classes, let me know.

I solved the problem, Anton – I was using Director and Movie instances, when I should’ve been using their objectIds.

Awesome!

Glad you solved it!

Best Regards