Sort order of related data

Hello
I am just looking for confirmation here, When I get the related data for a specific parent, will I get them in the order they were added as relationships? In other words, will the order of the returned list be the same as order I see on the consol when I click on the “related cell”
Thanks

1 Like

Hi SnakeEyes

Yes, you can use “setSortBy” for loading relations in the same way as for retrieving table records

const queryBuilder = Backendless.LoadRelationsQueryBuilder
  .create()
  .setRelationName( 'NAME-OF-RELATED-COLUMN' )
  .setSortBy( 'created' )

Backendless.Data.of( 'PARENT-TABLE-NAME' ).loadRelations(parentObjectId, queryBuilder )

In the Console, as far as I remember by default sorting is enabled by “created” column

Regards, Vlad

Oh I see, the only confusion here is that when the related item is created , it could have create date time which would be different from when you performed the relationship setup.

Ie Related data was created last month
but you set the relation today.

So what does create date time really represent in this case ? I mean is it basing the order on when you set it or when you created it … The console seems to maintain when you set it, so it could be some hidden create date of relation?

no, there is no creating date of establishing relationship, column “created” points to date of creating object in the DB

Hmm it is really interesting then the behavior I am observing which is returning the related items in the order I established them. I also flipped them and I got the correct flipped order .
It actually works as I wanted but I was just trying to understand/confirm things

maybe if you don’t use any sorting you will receive relations list in order they are stored for parent object, but I’m not sure about that

Thank you. I guess so :slight_smile: