Implement automatic model relation resolving.

Implements automatic resolving of model relations when performing model queries.