Autoload doesn't work as expected

I had used this in my javascript code: “return Backendless.Data.of( “order” ).findById(saveOrder.objectId);” to receive an order object by its objectId.
I have “order” table and there is 1to1 relationship on “client” table and 1to1 on “dealer” table, order (dealerId and clientId )and I have turned on “autoload” and the problem is that every retrieve request on the same object returns a different results, sometime it returns dealer object and client object is null, sometimes the client object but dealer object null and finally sometimes returns the both null.

Hi @Hassan_Serhan!

Can you provide your App ID?

Regards, Andriy

Is there any news? @Andriy_Konoz

I’m investigating problem

Regards, Andriy

Can you also specify actual tables in which this problem occurs? Currently it is not enought information for narrowind down problem.

Regards, Andriy

Is there a way to talk privately?

Unfortunatelly no. Private topics available only for holders of Backendless Pro-version.

Regards, Andriy

But if you have to share some sensitive information - you can send it via direct messages.

@Hassan_Serhan I read your message and removed your messages with sensetive information.

I will look at your problem.

Regards, Andriy

I will be waiting your reply.

Thank you,
Best regards

Hello @Hassan_Serhan

I just checked the API Service, and I can see that you’ve got several setRelation (without await) invocations which are running asynchronously and then without waiting a result you load the object by id, so you algorithm is:

  1. save an object
  2. assign relation-1 to the object
  3. assign relation-2 to the object
  4. assign relation-3 to the object
  5. assign relation-4 to the object
  6. assign relation-5 to the object
  7. load the object (findById) with autoload

The setRelation method is async operation and when you request the object from the server there is no guarantee that all the relations above are already established, so that’s why you get a floating result

to solve the problem I can recommend you use Promise.all([....])

const savedObject = await save(...)

await Promise.all([setRelation(...), setRelation(...), setRelation(...), setRelation(...)])

return findById(....)
1 Like

Ah got it. But in my code I have:
“Backendless.Data.of( “user” ).setRelation(saveUser,“To”,[getUser.objectId] );”

Where I put the await Promise.all?

You must put Promise.all before find query since you want to be shure that all data-objects were created before query.

Regards, Andriy

1 Like

Thanks a lot! It works…