'use strict';
module.exports = function (City) {
City.GetCurrentPopulation = function (req) {
var population;
City.app.models.Pupulation.find({where{id:req.id}}, //This line //gives me an error that cannot read property 'find' of undefined
function(req.res){
population=res.population;
});
response='Population for ' +req.cname ' is' +population;
req(null, response);
};
City.remoteMethod(
'GetCurrentPopulation', {
http: {
path: '/GetCurrentPopulation',
verb: 'GetCurrentPopulation'
},
returns: {
arg: 'startdate',
type: 'string'
}
}
);Run Code Online (Sandbox Code Playgroud)
有一个模型城市,我想访问另一个模型,如"population.find(一些过滤器)"如何做到这一点?
我有一个用城市模型编写的远程方法.我试图访问人口记录的地方
var countryp = population.find(其中{id:4});
var currentpopulation = countryp.Totalpopulation;
它给出了一个错误population.find不是一个函数.
请建议如何做到这一点.