Support Topics Documentation Slack YouTube Blog

Load relations while fetching data


(Rajasekhar Puligadda) #1

How to load specific table relations in queryBuilder while fetching data in backendless using js?


(Oleg Vyalyh) #2

Hi, Rajesekhar.
Have you tried the examples from here https://backendless.com/docs/js/data_single_step_retrieval.html ?


(Rajasekhar Puligadda) #3

I have two tables A(parent), B(child).
A table have 1:N relationship with B table.

I am fetching B table data using A table. How i can get particular fields in B table in this case?

how i can set SortBy for created field in B table?


(Vladimir Upirov) #4

Hello
You can not get it in a single api-call, it can be done with another api-call
https://backendless.com/docs/js/data_two_step_retrieval.html

When you request child records in another api-call you can use paging, sorting, propsFiltering


(Rajasekhar Puligadda) #5

In the example, how i can sort the data using " loadRelationsQueryBuilder"?


(Vladimir Upirov) #6

Oh, sorry, it’s not supported yet, but I’ve created an internal ticket to add this, for reference ticket is: BKNDLSS-18026, we will fix it as soon as possible and notify you here.

As workaround I can propose you to use " Inverted Relation Retrieval", here is a doc:
https://backendless.com/docs/js/data_inverted_relation_retrieval.html

var childStorage = Backendless.Persistence.of( "CHILD_TABLE_NAME" );
var queryBuilder = Backendless.DataQueryBuilder.create();
queryBuilder.setWhereClause( "PAREN_TABLE_NAME[RELATION_NAME].objectId='PARENT_OBJECT_ID'" );

queryBuilder.setSortBy( “age” );
var sortedRelations = await childStorage.find( queryBuilder );