6.0.4 Backendless JS SDK loadRelations problems

Just updated my code to use the latest backendless SDK from 5.8.4 but I have a problem with the following code not returning related objects:

Snip …

private workspaceStore = Backendless.Data.of('Workspace');
return this.workspaceStore.findById<Workspace>({
      objectId: objectId,
      loadRelations: ['site', 'contentType', 'region']
    })

Has something changed in backendless SDK with regards to the way relations are loaded? I cannot see anything in the documentation.

Many thanks

Steven

Hi @Steven_Salmon,

We’ll take a look and back to you as soon as possible.

Best regards,
Yevgen

@Steven_Salmon,

Could you be so kind to provide us your APP-ID ?

Thank you in advance.

Sure: E69227A1-ECAD-2EC3-FF57-0530DD384800

Hi @Steven_Salmon,

I’ve reproduced the issue and internal ticket was created - BKNDLSS-22103.
Sorry for inconvenience, we’ll update you when it will be fixed.

Thank you,
Yevgen.

Thank you. I look forward to your response. Many thanks. Steven

Hello please could you advise if any progress has been made on fixing this issue?

Hello @Steven_Salmon

We are working into it. At the moment, a solution to this issue has not yet been made, as soon as there is some progress on this issue, we will additionally inform you in this topic.

Please try this approach:

private workspaceStore = Backendless.Data.of('Workspace');
return this.workspaceStore.findById<Workspace>(objectId, {
  relations: ['site', 'contentType', 'region']
})

Or this one:

private workspaceStore = Backendless.Data.of('Workspace');
return this.workspaceStore.findById<Workspace>({
  objectId: objectId,
  loadRelations: 'site,contentType,region'
})

It will work

1 Like

Hi @stanislaw.grin thank you for this. Is this the official answer or just a temporary but workable solution?

Hello @Steven_Salmon

Yes, this is the right way to load relations while load object by its id.

Let me explain a few points:

  1. to load an object by its objectId you should pass the first parameter “objectId” as a “String”

  2. if you have external databases which is supported in Pro and Manage installations and where some tables might have more than one primary keys you can pass the first arguments as an object, for example, table Foo has two primary keys: “id” and “name” and to find the object you have to pass as the first argument an object with this keys: { name: “bob”, id: “12345” }

  3. if the first argument is an object all the properties of the object will be added to url as query parameters, “?name=bob&id=12345”

  4. to use other features such as “load relations”, “filter props” for that object you can pass as the second argument DataQueryBuilder instance or and object with corresponding properties

as you can see this is not a good way to mix the primary keys and query-builder params in a single object

you can find these signatures by the following link https://github.com/Backendless/JS-SDK/blob/master/backendless.d.ts#L1019

we have fixed the signature for Typescript in version 6.0.0 of the JS-SDK, so make sure you use the latest one.

Regards, Vlad

1 Like

Thank you @vladimir-upirov for the advice and information and also @stanislaw.grin for the code example. Fully understand and my code has been updated which is working now. Thank you.

1 Like