Get Count of One to Many Records - for non autoload column ( iOS )

I have a column post message (In Post Table) -> It contains many comments (In Comments Table)-> (One To Many)

I don’t want to use autoload (because of large data)
How can i get comment count from the Post table
Please give sample for iOS regarding this.

Any update?

I am not good with Obj-C/Swift, so instead of showing a coding sample, I will describe how to achieve this:

If you need to determine object count or entities related to another object, you can run the following query (with the “find” request) against the Comment table with PageSize set to 1 (yes, you will load only one object, but the response will also tell you how many total “child” objects are available on the server:

Post[comments].objectId = ‘parent-post-objectId’

where:

comments - the name of the relation column in the Post table
parent-post-objectId - objectId of the Post object for which you need to get the comments

The response will be an instance of BackendlessCollection, which contains the “totalObjects” property. The property will give you the total number of comments for the post.

Regards,
Mark

Here in my current situation is - i am loading all the post from Post table (i have to show the comments count in the first page) - while loading the Post table i have to get the comment count, not to send a separate request for each post to get the comments,

Your options are:

    Maintain count as a property of every post object or

    Create a custom API service which will run all the queries, get counts, etc and return a unified response back to the client.

Mark

As per option 1 : You mean manually i have to update the count property in Post table whenever a new comment added for a post?

Also can i do the auto increment for a post to maintain the view count? - if so how autoincrement

As per option 1 : You mean manually i have to update the count property in Post table whenever a new comment added for a post?

If you want to avoid multiple calls to get the values, then it is one of the options to do that.

As for the auto-increment at the database level, there is no built-in mechanism to do it. It can be done with a custom event handler (Cloud Code) though. Another option is to maintain a separate counter using the following API (but that will not help with reducing the number of API calls):
https://backendless.com/documentation/utilities/ios/ut_atomic_counters_ios.htm