 util = require 'util'
 _ = require 'underscore'
 Utils = require 'backbone-orm/lib/utils'
-JSONUtils = require 'backbone-orm/lib/json_utils'
 
 module.exports = class RESTController
 

      cursor.toJSON (err, json) =>
        return res.send(404) if err
        return res.json({result: json}) if req.query.$count
        return res.json(json) unless @renderer

        # TODO: intgrate the cache -> would need to be done as part of the fetch
        # TODO: can be optimized by using one model, etc
        JSONUtils.renderModelsJSON _.map(json, (model_json) => new @model_type(@model_type::parse(model_json))), @renderer, @render_options or {}, (err, json) =>
          return res.status(500).send(error: err.toString()) if err
          res.json(json)

    catch err
      res.status(500).send(error: err.toString())

        success: =>
          json = model.toJSON()
          json = _.pick(json, @white_lists.create) if @white_lists.create
          return res.json(json) unless @render

          # TODO: intgrate the cache -> would need to be done as part of the fetch
          @render req, json, (err, json) =>
            return res.status(500).send(error: err.toString()) if err
            res.json(json)
        error: -> res.send(404)
