How to get the count of an objects relation

Hi, how could I get the count of related objects?
I have an object called ‘Course’ and it has a one to many relation with another object called ‘Sessions’.
I want to get the number of ‘Sessions’ in a ‘Course’


This is my page here. At the bottom see we have the courses and under the course title I have the number of sessions.


This is my codeless logic so far. How do I use the where clause to get the number of items.

Hi @Breldan_Muthaka,

use the following query against the Sessions table:
Courses[sessions].objectId = 'your-course-object-id'.

Regards,
Stanislaw

Thanks, sir

I was able to achieve the same results to show the count of sessions for different courses as follows.


Is there perhaps a disadvantage to my approach?

If you have more than 10 sessions in a course, you won’t get them because you’ve limited the request to just 10 entries. The maximum value that can be specified is 100 entries. Thus, if you are sure that you will never have more than 100 sessions per course, then your solution is fine, but I would not advise doing this, since you are loading entire objects just to get their length, while the solution that I suggested to you will return the number of sessions at once, even if there are more than 100 of them.

Regards,
Stanislaw

I do not understand your solution completely. I am getting the course object ID from “our__programmes” repeater data item.
I’m not precisely sure how I would structure the where clause.


I have tried using the method prescribed. I am not able to structure the where clause correctly, as such the logic returns the count of all sessions rather than the sessions associated with the course.

You missed single quotes surrounding the objectId in the where clause.

1 Like