What's the optimal way to get a related object without autoload after user login?

I have a relationship from my Users table to another table called “Org”. When a user logs in, I need to get information about their org, e.g., the organization name. If I turn on autoload for the org column in the Users table, I can access the org table and all the org properties. I know there are some performance/scalability issues with autoload so I want to find out if there’s an efficient way to get the org object when a user logs in without using autoload. Some ideas I’m considering and would like your feedback on:

  1. Use autoload. Pros: It works and the code is clean. Cons: Not sure if performance will be an issue if the number of users or organization grows significantly.
  2. After user login, run a query to get the user’s data object again and use the addRelated QueryOption to make sure I get the org object. Pros: It should scale better than autoload. Cons: It seems inefficient to run a query for a user object I already have from the login response.

Are there other options I should be considering? Is there a chance Backendless might include the objectId for relation properties when autoload isn’t turned on? This would allow developers to get the related object quickly and efficiently using the findID query.

Thanks,
Jeff

Hi Jeff,

To get an Org for a user, it is not necessary to get the entire user object. As long as you know something about the user (his email, objectId or anything else that would be a unique item), you can load the related Org objects with the following whereClause:

Users[ org ].email = 'user-email-address'

or

Users[ org ].objectId = 'user-objectId'

These queries must be sent to the Org table and you will get a collection of Org objects satisfying the query.

Hope this helps.

Mark

Hey Mark, would you show how to do this in Android? How to query a TableOne and return only the objects where the field “tableTwoReference” matches the objectId of another table, TableTwo.

I have been trying to do this for some time without success. My where clause looks like this:
String tableTwoObjectId = “actualId”;
String whereClause = “tableTwoReference = '” + tableTwoObjectId + “’”;