Group by not working in 2 Step approach

I have a forum application with a forums table on top, having relations to the posts table. The 2 step approach works pretty well as long as I don’t use aggregates. The posts table has a relationsshipt to the users table in field “likes”. So I want to return the number of likes with each post. Unfortunately, I only get back one record with the overall number of likes for ALL posts. The GROUP BY doesn’t seem to work here … Any idea?

const queryWithPosts = Backendless.LoadRelationsQueryBuilder.create()
.setPageSize(5)
.setProperties([
‘description’,
‘created’,
‘objectId’,
‘ownerId’,
‘locationId’,
‘Count(likes) as totalLikesCount’,

])
.setGroupBy('objectId')
.setSortBy('locationId DESC')

queryWithPosts.setRelationName('posts');

const forumPosts = await Backendless.Data.of('forums').loadRelations( 
                          forumId,
                          queryWithPosts )

It is hard to say precisely without seeing your schema. Generally speaking to get the number of likes for each post, you’d need to groupBy posts.

Hi Mark,

it’s as I said: FORUM table has a POSTS field which is a relationship to the POSTS table. POSTS table has a LIKES field which is a relationship to the USERS table. If you wanna check… My APP ID is 0C283C9B-B5F1-34C7-FFBA-7595644DBD00. The service is getRecentPosts.

Thanks,
Thomas

This is what I came up with (using REST, but it should be straight-forward to translate to API):

/data/Posts?property=Count(likes)&
            property=description%20as%20postDescription&
            property=Forums[posts].title%20as%20forumTitle&
            groupBy=objectId

This is the result I got:
image

Regards,
Mark