Getting objects in inverse queries

We have a tableB that is a child of another tableA (tableA has 1:many relations to tableB). Also, tableA has a 1:1 relation to another table, call it tableC, which has columns c1, c2, c3.

We are able to load an object from tableB along with an individual related property in tableC. We can do this by specifying that we want an object of tableB described by

“tableB[tableA].tableC.c1” — this works.

However, we would like the entire object from tableC (not just one property but all the properties of the related object). But when we specify that we want a property of tableB like

“tableB[tableA].tableC” (i.e. without specifying a specific property in tableC)

we do not get anything back from the call to the database. We’re hoping to get an object back from tableC. Is this not possible?

In addition, tableA also has 1:N relations with yet another tableD. We will want to retrieve an array of objects from tableD that are indirectly related to an object in tableB, by querying tableB. Possible?

What is the primary table to which you send the query?

If you send your query to tableC, you will be getting complete C objects. Otherwise, you would need to include in the query all the properties/columns of tableC to be returned in the response.

right so we have to specify the precise columns of TableC when we send a query to TableB… I was afraid of that. Doable though.

However, how can we get an array of things from TableD (which is related to TableA via 1:N relations, by sending a query to TableB? Could we specify the column in TableD and get back an array of values?

If you’re asking about an array of related values for each primary object, the answer is no.

OK, thanks. I tested this (asking for a specific property in TableD via a query to TableB) when there were 3 objects in TableD that matched… the query just returned one of them :roll_eyes:

Say you have table A.
Table A has a one to many relation to table B.
When you retrieve objects from table A and ask for related objects from B, you will not get an array of related objects. For that there is a separate API call to get related Bs for a specific object from A.

Thanks Mark,

In that (straightforward) case, we can simply ask for the related objects from table B by wiring up the “relations” input for the Load Table Objects block which queries table A… and we then DO get an array of related objects, I’m pretty sure :grinning:

Yes, you’re right… I was describing a use-case while thinking about another one. Let me rephrase then:

Say you have tables A, B and C.

table A has one-to-many with B
table B has one-to-many with C.

You retrieve objects from A.

The only way to get related Bs for each A and to get related Cs for each B is by using “relations depth”. See the API doc here: Retrieval with Relation Depth - Backendless REST API Documentation

While relation depth is nice, I do not recommend using it. It will penalize your app with a performance hit. Additionally, you will not be getting all related objects, the server will provide only a snapshot of data.

Hope this helps.

Mark

Yes, that makes perfect sense… getting 1:N times 1:N objects seems like a bad idea, generally. Thanks for all the insight and quick responses :pray: