Unable to set Relation in users table (Swift 4)

Hi all,

I seem to be having trouble setting a 1:N relation on the Users table with Swift 4 and the iOS SDK.
Using the sync “addRelation” method, I keep getting this error:

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #ffffff}
span.s1 {font-variant-ligatures: no-common-ligatures}

Optional(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.> )

It seems as though the objectID string that I pass in is getting ignored (also verified that the value that gets passed into the function call is not null).
There is this previous issue that I had brought up before, that seemed to have been resolved, but maybe has resurfaced? (Not the exact same issue, but the same error).

http://support.backendless.com/t/backendless-4-0-set-relation-does-not-override-previous-value

Also, when we set a relation against the “special” users table, how should that be done?
I have tried both the following signatures, and they both result in the same error:

Backendless.sharedInstance().data.of(BackendlessUser.self).setRelation( ... )
Backendless.sharedInstance().data.ofTable("Users").setRelation( ... )

Renato

Hello Renato,

I’ve checked and it works fine for me. Here are my examples:

// Set 1:N relation from the Person table to the Users table
let dataStore = backendless.data.ofTable("Person")!
 dataStore.setRelation("friends",
 parentObjectId: "CD9D1004-...",
 childObjects: ["94D3682F-...", "C1961C51-..."],
 response: {result in print("Relation set")},
 error: {fault in print("Error: \(fault!.message)")})
// Set 1:N relation from the Users table to the Address table
let dataStore = backendless.data.of(BackendlessUser.ofClass())!
 dataStore.setRelation("location",
 parentObjectId: "C1961C51-...",
 childObjects: ["34D280D9-...", "FAA30D10-..."],
 response: {result in print("Relation set")},
 error: {fault in print("Error: \(fault!.message)")})

I’m using Xcode 9.1, Swift 4, iOS-SDK 4.0.18
Regards, Olga

Thank you Olga, I was mistakenly adding the entire object to the “childObjects” parameter in the function call, instead of just the objectIDs.

It is however a little misleading that the signature of the “childObjects” parameter is of type [Any] - which almost leads me to believe it should be the objects themselves, even though I now see that the documentation says it should be an array of the objectIDs. Maybe “childObjects” of type [String] would be clearer, to infer just the objId value?

Hello Renato,
Thanks for the idea, we have it on our roadmap. Also we have the clear examples here.

Regards, Olga