23
Views
9
Comments
Solved
Possible ways to get count of child entity records in preparation of parent
Application Type
Traditional Web
Service Studio Version
11.10.0 (Build 34712)

Dear all,

consider having a parent - child entities : Classroom and its students. A classroom has one or more students, while each student can only be in one classroom. 

In de preparation of my webscreen Classroom, I want to add a column/attribute to get to count of its students, just a total number of students in this classroom.

What are the possible ways to get this count in the preparation while still showing all attributes of the current classroom entity?

I am new to OutSystems, hope you can help me by answering this question!
Thanks in advance!

Regards,

Kelvin

Rank: #66
Solution

Hello Kelvin, 

You can do this with Group By.

See the gif of how to do Group By


Attached example oml.

Classroom.oml

Rank: #49151

Thank you, this answer has solved my problem! 

Rank: #88

Hi Kelvin ,

You can use group by classroom  and get count of students.

like this

and also you can apply filter by class.


Hope this will help you.

Regards

Rahul

Rank: #285

Hi Kelvin,

For your use case, you need to have ClassroomId in Students entitiy as this enforces one to many relationship. and to get count of students per classroom, Use students aggregate inside preparation and group by using ClassroomId by clicking on Aggregate Menu menu of ClassroomId column and choose Group By ClassroomId and then take a count on students by again clicking on Aggregate Menu menu of Student Id column and choose Count .


Rank: #285

Hi Kelvin,

Here i have a shared a working OML, please take a look at the GetStudents aggregate in preparation.

Hope it helps, Thanks 

StudentsPerClassroom.oml

Rank: #49151

Dear Rahul,

thanks for your answer! When using a group by, I can use the count on number of students, but I can not show other attributes of classroom anymore. 

Sample what i want to show:

classname - classnumber - teacher name - number of students

Attributes classname and classnumber comes from classroom entity
Attribute teacher name comes from teacher entity ( with or without join )
Attribute number of students should be derived from ClassroomStudents entities

Regards,

Kelvin

Rank: #66
Rank: #285

You need to select all the required columns and use group by by the selected attributes and then take a Count over students.

Rank: #66
Solution

Hello Kelvin, 

You can do this with Group By.

See the gif of how to do Group By


Attached example oml.

Classroom.oml

Rank: #49151

Thank you, this answer has solved my problem! 

Rank: #1755

Hi Kelvin

Its a property of SQL to return only the computed function.

You should be grouping on an aggregate with two sources classroom and students as suggested by @Shweta Gedam and since you are involving the Classroom Id in the group it will have the same students even if you group on all the attributes of the Classroom, that is exactly what you need to do.

The grouping will be have to be done for all the extended relationships of the classroom table like teacher name assuming you are using the teacher id in the classroom table by adding another source of the teacher in the same aggregate.

Hopefully this is understood.

Thanks 

Ashish