I use yii framework that implements Active Record pattern as ORM base. It has CActiveRecord class that is a table wrapper class with attributes reflecting table columns. So each object of this class represents a database row.
Wiki says about Active Record pattern:
Active record is an approach to accessing data in a database
and
A database table or view is wrapped into a class. Thus, an object instance is tied to a single row in the table.
So far so good.
But where should I put complex raw sql query that retrieves statistics data for example?
And, more generally, where should I put methods that retrieve some data that can not be an active record object (like data retrieved with aggregation queries) or if I knowing do not want to retrieve an object but an array instead for example?