One-to-Many Child Count

  
Hi,

I am trying to evaluate the capabilities of this amazing platform, during my challenging dive through all the cool stuffs you have i faced one confusion, i have the following entities:



and i am using the list page to show the projects using aggregate and i want to display the count of tasks in each project using the badge widget:


but the problem that i am not able to get the count of tasks against the projects in the aggregate as an attribute

any advice ??
This was a bug for a while on some early versions of 9.0.  See this thread for details http://www.outsystems.com/forums/discussion/14531/aggreggate-count-property-with-wrong-value/
Curt Raddatz wrote:
This was a bug for a while on some early versions of 9.0.  See this thread for details http://www.outsystems.com/forums/discussion/14531/aggreggate-count-property-with-wrong-value/
 Thanks Curt Raddatz for your reply, but actually i do not know how to reach the point they are talking about in that post.

more over i am focusing on having a columns in the projects list contains a subquery of tasks related to this project, but i do not know how to reach that point. 
 
Hey Mohamed,

Better way would be to write Advance query and select specific columns and use "count()" function to get Counts of tasks associted with projects.

Suraj
Suraj Borade wrote:
Hey Mohamed,

Better way would be to write Advance query and select specific columns and use "count()" function to get Counts of tasks associted with projects.

Suraj
 Dear Suraj,

Thanks for your reply

i tried to do what you advised to do by adding SQL instead of using the Aggregate Widget, but the problem still related to the count, i added it to the query Tasks_Count but when i run test query output it still not shown in the output grid since it is not related to any of the selected entity output.


 
I was able to implement what is required and as usual for OutSystems Platform in a very easy way, by simply adding a new structure holds the query extra columns 



and use it as an output for the query i managed to have this done.

Hey that's great you solved it.

You just need one variable inside structure because you are selecitg count which is unique.

Cheers !


Suraj Borade wrote:
Hey that's great you solved it.

You just need one variable inside structure because you are selecitg count which is unique.

Cheers !

 
 Do you mean like an identifier for the structure is an ID, like in my case using the Project.ID since it will be unique, right?
 
Inside the subquery, you are calculating the count for specific ProjectId, so it is correct. It will return count of tasks for each unique ProjectId. (It's giving you list)

If you want to get count for single Project, just pass the ProjectId as input parameter and use that condition in where clause.

So after adding ProjectId as input parameter your codewill look like 

where {Project}.[Id] = @ ProjectId.

But in case of list no need of input parameter.
You just need to check two more things
1. If there is any IsActive variable in Project table

2. If there is any IsDeleted variable in Project table

if these variables are there, modify your where condition lke

{Project}.[IsDeleted] = 0 and
{Project}.[IsActive] = 1