var _ = require('underscore');

module.exports = function(mongoose){

	_(mongoose.Model).extend({

		getRoot: function(options, callback){
			this.find(options.req.query.filters)
				.sort(options.req.query.sort)
				.skip(options.req.query.offset || options.req.query.paginate && options.req.query.paginate.offset)
				.limit(options.req.query.limit || options.req.query.paginate && options.req.query.paginate.limit)
				.exec(callback);
		},

		sgRouteCheckoutGet: function(options, callback){
			this.getRoot(options, callback);
		},

		sgRouteCheckoutPut: function(options, callback){
			callback('Route checkout put on model not supported');
		},	

		sgRouteCheckoutPost: function(options, callback){
			this.create(options.req.body, callback);
		},

		sgRouteCheckoutDelete: function(options, callback){
			callback('Route checkout delete on model not supported');
		}

	});

};

@@ -131,24 +131,202 @@
 llback)%7B%0A%09%09%09
+var sort = options.req.query.sort;%0A%09%09%09if(!sort && options.req.query.sortBy) %7B%0A%09%09%09%09sort = %7B%7D;%0A%09%09%09%09sort%5Boptions.req.query.sortBy%5D = options.req.query.sortHow %7C%7C 'asc';%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09
 this.find(op
@@ -360,34 +360,16 @@
 %09%09.sort(
-options.req.query.
 sort)%0A%09%09

update sort