How To Retrieve The Related Projects In A Program

I have two models Projects and Programs. both of them are in relation. WHen I submit a new project then I must have to select a related program in dropdown menu, and also specify that whether the project_status is completed or inProgress.

Now I want to display the Total no of projects in the program detail view and also the total no of projects that are inProgress and also the total no of projects that are Completed.

THanks in advance.

Look into the relations options (HAS_MANY,BELONGS_TO,etc) One of the options has to do with STAT or COUNT. Not sure if you can set conditions thou.

Otherwise a function of two in the model that does the query and returns the value. You could use namedScopes in the query.

Thanks dear. I have already solved it.

And you solved it…How? Others might like to know :)