Actually, David is spot on.
Fetching models is an asynchronous operation, regardless of whether you do it with promises or callbacks. Makes no difference, and doesn’t make much sense in any case to expose the Model (as opposed to the result of a model query) to the view…
What you probably want to do is some sort of utility method (a service would be a good place for this, assuming you want to use it on multiple controllers.
The promise version of something like this might look like:
// in services/RenderUtility.js
module.exports.renderData = function(data){
return res.view(’some/view’, { data: data });
}
//usage looks like
Foo.find().then(RenderUtility.renderData);
or for a bit more configurability, you could declare a function that returns a function:
module.exports.renderData = function(viewName){
return function(data){
res.view(viewName,{data: data});
}
}
which you could use like
Foo.find().then(RenderUtility.renderData(‘some/view’));
note the difference there where i’m calling the function inside the promise resolution.
R