Why I can't get the objectId of a relational column?

Hey everyone.

I have 2 tables, “orders” and “clients”, in the first one there is a relational column named “client” with the second table, I am using this code to get the objectId of client in the “orders”:

var reserveOrdersFound=await Backendless.Data.of( “orders” ).find(queryBuilder);
await Backendless.Data.of( “clients” ).findById(reserveOrdersFound[0].client.objectId);

NOTE: “reserveOrdersFound[0].client” returns the client for me.
So I want to know how to get this objectId in the second line and why this is not working?

1 Like

Can you specify how you construct the queryBuilder object used in the call below? Specifically, what properties you configure in it?

This is not related cause “reserveOrdersFound[0].client” returns the client for me.

the reponse as this form:
" [
{…

}, …
“ownerId”: “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”,
“updated”: null,
“objectId”: “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”
},
“updated”: xxxxxxxxx
}
] "

When you call findById without query builder argument, you get only the object identified by its objectId. In order to get relations for that object, you need to invoke the following:

Backendless.Data.of( “TABLENAME” ).findById(objectIdValue, queryBuilder);

In the queryBuilder argument you need to specify what relations you need the server to return.

Regards,
Mark

But my problem that I am trying to get the objectId cause I don’t have it.

Regards,

Are you saying that the following doesn’t have a value?

I have found the solution right now:

var found = await reserveOrdersFound[0].client
return found[0].objectId

Regards,

I do not think you need to put await in here:

var found = await reserveOrdersFound[0].client

In fact, you can shorten the two lines into this:

reserveOrdersFound[ 0 ].client[ 0 ].objectId

Yup, thanks for your quick response!

Have a nice day!

1 Like