Backendless Support
 
Solved

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}

  1. 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/topic/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:

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

Renato

Leave a Comment

Comments (3)

photo
1

Hello Renato,

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

  1. // Set 1:N relation from the Person table to the Users table
  2. let dataStore = backendless.data.ofTable("Person")!
  3. dataStore.setRelation("friends",
  4. parentObjectId: "CD9D1004-...",
  5. childObjects: ["94D3682F-...", "C1961C51-..."],
  6. response: {result in print("Relation set")},
  7. error: {fault in print("Error: \(fault!.message)")})

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

I'm using Xcode 9.1, Swift 4, iOS-SDK 4.0.18

Regards, Olga

photo
1

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?

photo
1

Hello Renato,

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

Regards, Olga

photo