Added cast support in Model.aggregate

It's painful to manually cast several ids to use in `aggregate`.

Since the cast function is now in a separate module (instead of inside `query.js`), it's simple to integrate it with `aggregate.js`.