Related objects not returned with user

I am using the Javascript api.
In my users table I have a related object to another table.

When I call Backendless.UserService.getCurrentUser() the related column is not included in the user object. How can I include that in the data that is returned?

I would like it to retrieve either the related objectId or preferably the entire object.

Hello, @Tony_Goodchild.

You cannot do this using the getCurrentUser () method.
But you can do it this way:

const user = await Backendless.UserService.getCurrentUser(true)
const query = Backendless.DataQueryBuilder.create().setRelationsDepth(1)
const userWithRelations = await Backendless.Data.of('Users').findById(user.objectId,query)
return userWithRelations

Best regards, Nikita.

Thanks @Nikita_Fedorishchev that works :slight_smile:

I ran into this problem and found this thread, but I need a better understanding of the next step. For me I tried saving the returned user object ( with related objects ) using the setCurrentUser method. I wanted to cache the object so I could run getCurrentUser and have the same user object with related objects accessible on other pages. However, once I navigate to another page the related user objects are not returned with getCurrentUser method. It works on the first page…the one with the setCurrentUser method, but any other page only returns the user object without related objects. Is there a way to have setCurrentUser maintain the full object across pages?

Here is a breakdown of what is happening:

Page 1

  1. Run query with depth of 1 Backendless.Data.of(‘Users’).findById(user.objectId,query)
  2. Run setCurrentUser(obj, true) with the result of #1.
  3. Run getCurrentUser() full object with related objects is returned.

Page 2

  1. Run getCurrentUser() returns user object WITHOUT related objects

Is this expected behaviour? I would assume that whatever I set as the current user would maintain the full object and not drop the related objects. If dropping the related objects is expected then I need setup my own cache.