Skip to content

Commit

Permalink
avoid overwriting req.model if defined already
Browse files Browse the repository at this point in the history
  • Loading branch information
nateps committed Mar 22, 2016
1 parent fe0d9d8 commit 74059d1
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/Backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ RacerBackend.prototype.createModel = function(options, req) {
RacerBackend.prototype.modelMiddleware = function() {
var backend = this;
function modelMiddleware(req, res, next) {
// Do not add a model to the request if one has been added already
if (req.model) return next();

// Create a new model for this request
req.model = backend.createModel({fetchOnly: true}, req);
// DEPRECATED:
req.getModel = function() {
console.warn('Warning: req.getModel() is deprecated. Please use req.model instead.');
return req.model;
};

// Close the model when this request ends
function closeModel() {
res.removeListener('finish', closeModel);
res.removeListener('close', closeModel);
Expand Down

0 comments on commit 74059d1

Please sign in to comment.