                 query = args.template
               else
                 template = args.template
+                query = _.clone(args)
+                delete query.key; delete query.template
+                query = null if _.size(query) is 0
             else
-              template = _.extend({}, args)
-              delete template['key']
+              template = _.clone(args)
+              delete template.key
+
+            # template
+            if template
+              if query
+                relation.cursor(model, field, query).toModels (err, models) ->
+                  return callback(err) if err
+                  JSONUtils.renderJSON models, template, options, (err, json) -> result[key] = json; callback(err)
+
+              else
+                model.get field, (err, related_model) ->
+                  return callback(err) if err
+                  JSONUtils.renderJSON related_model, template, options, (err, json) -> result[key] = json; callback(err)
 
             # query
-            if query
+            else
               relation.cursor(model, field, query).toJSON (err, json) -> result[key] = json; callback(err)
-
-            # template
-            else
-              model.get field, (err, related_model) ->
-                return callback(err) if err
-                JSONUtils.renderJSON related_model, template, options, (err, json) -> result[key] = json; callback(err)
 
         else if key is '$select'
           queue.defer (callback) -> JSONUtils.renderJSONKeys model, args, options, (err, json) -> _.extend(result, json); callback(err)


            if args.$query
              query = args.$query
            else if args.$count
              query = args
            else if _.isFunction(args)
              template = args
            else if args.template

        if _.isArray(value)
          #todo: check bug, incorrect models are being returned, they contain themselves? {0:model, 1: model, <correct model fields are here>}
          value = (val.toJSON() for val in value)
        else if value and value.toJSON
          value = value.toJSON()
      callback(null, value)

