Adding group conditional for calculateRating works properly with postgresql

psql error:
ERROR:  column \"%Model%.id\" must appear in the GROUP BY clause or be used in an aggregate function