Fix ORM aggregate functions