How to sort data retrieved as related data

I have 2 tables. Photos and comments

each photo a 1:n relation with multiple comments.

I am able to load the comments as a relation to each photo as seen here

I understand sorting data at the top level. But i dont understand how to sort the related data. is there a way to sort the data returned from the relations? specifically, i want to order the “comment” array by the date created for each object

I want to sort the comments by date created. is this possible? should my comments table have an objectID column. the photo objectID. I could then use a ‘where’ clause to get the photo comments instead of the relation.

my table structures are as such
locations

comments

Hi Jared,

What you need to do is add the following to the URL:

sortBy=comment.created

Regards,
Mark

Hi @mark-piller ,

I am attempting to do the same - but cannot achive the functionality:

I am using the following URL
/Chats/{chatid}?loadRelations=MessagesInChat,UsersInChat&relationsPageSize=100&sortBy=MessagesInChat.created desc

I am trying to retrieve the “MessagesInChat” sorted by deceding creation date

Please assist me with this

@Anuj_Nayyar

sortBy=MessagesInChat.created

Hi Marina,

My url contains this already, but it is not achieving the desired behaviour

What behavior do you have now? Is your request being processed?

I am retrieving the desired data:
An array of related objects - however I am unable to apply a sort the related objects

@Anuj_Nayyar, what is your application ID?

Was this ever resolved? Dealing with the same challenge, trying to sort relations as they are returned from the database…

Hi, @Alex_Klein

The issue is resolved in the next topic - Load relations operation for transactions?
Please let us know if this is not the case, and we will continue the dialogue.

Regards,
Serhiy

Yes, I guess it’s resolved (sorting relations is not possible when getting parent object(s) with relations… we need to fetch relations separately and then we can use “sort by”). Thanks for the follow up :grinning: