 
   options.toJSON ?= (items, req) -> items
 
-  seek = (constraints, callback) ->
+  seek = (request, constraints, callback) ->
     if collectionIsRelation
-      options.collection
+      collection = options.collection
+      if typeof options.collection is 'function'
+        collection = options.collection request
+      collection
         where: constraints
       , (err, items) ->
         items = [] unless items
         callback err, items
       return
 
-    constraints =
+    options.model.all
       where: constraints
-    options.model.all constraints, (err, items) ->
+    , (err, items) ->
       items = [] unless items
       callback err, items
 
   resource =
     id: options.urlName
 
-    load: (where, callback) ->
+    load: (request, where, callback) ->
       whereQuery = {}
       whereQuery[options.where] = where
-      seek whereQuery, (err, items) ->
+      seek request, whereQuery, (err, items) ->
         return callback err if err
         callback null, items[0]
 
     index:
       html: (req, res) ->
-        seek {}, (err, items) ->
+        seek req, {}, (err, items) ->
           if options.addPlaceholderForEmpty and items.length is 0
             blankItem = {}
             for property, defs of options.schema.definitions[options.name].properties

              items: items
              as: 'item'
      json: (req, res) ->
        seek {}, (err, items) ->
          res.send options.toJSON items, req
      default: exports.contentNegotiator

    create: (req, res) ->
      options.collection.create req.body, (err, item) ->
        res.send options.toJSON item, req



    destroy: (req, res) ->
      req[options.urlName].destroy (err, item) ->
        res.send options.toJSON req[options.urlName], req

    show:
      html: (req, res) ->
