私はbookshelf.jsを初めて使用し、node.js + MySQLプロジェクトでORMに使用しています。この単純なクエリでエラーが発生します。誰かが私が間違っている場所を教えてもらえますか?
//Get reviews for a service - TESTED
app.get('/api/review/:serviceID?', function(req, res) {
var serviceID = req.params.serviceID;
console.log("Service ID: " + serviceID);
new Review.query('where','serviceID','=', serviceID)
.fetchAll()
.then(function(reviews) {
if (reviews!=null)
res.send(reviews.toJSON());
else
res.send("No reviews found");
}).catch(function(error) {
console.log(error);
res.send('An error occurred in fetching reviews for service '+ serviceID);
});
});
ここで、review テーブルには、reviewID として主キーがあり、外部キーとして serviceID があります。これは私が得ているエラーメッセージです。
TypeError: Object [object Object] has no method 'forge'
at new Model.(anonymous function).Collection.(anonymous function
(d:\PMF\node_modules\bookshelf\bookshelf.js:146:24)
at app.get.serviceID (d:\PMF\app.js:121:15)
at Layer.handle [as handle_request]
(d:\PMF\node_modules\express\lib\router\layer.js:82:5)
at next (d:\PMF\node_modules\express\lib\router\route.js:110:13)
at Route.dispatch (d:\PMF\node_modules\express\lib\router\route.js:91:3)
at Layer.handle [as handle_request
(d:\PMF\node_modules\express\lib\router\layer.js:82:5)
at d:\PMF\node_modules\express\lib\router\index.js:267:22
at param (d:\PMF\node_modules\express\lib\router\index.js:340:14)
at param (d:\PMF\node_modules\express\lib\router\index.js:356:14)
at Function.proto.process_params
(d:\PMF\node_modules\express\lib\router\index.js:400:3)
at next (d:\PMF\node_modules\express\lib\router\index.js:261:10)
at jsonParser (d:\PMF\node_modules\body-parser\lib\types\json.js:96:40)
at Layer.handle [as handle_request (d:\PMF\node_modules\express\lib\router\layer.js:82:5)
at trim_prefix (d:\PMF\node_modules\express\lib\router\index.js:302:13)
at d:\PMF\node_modules\express\lib\router\index.js:270:7
at Function.proto.process_params (d:\PMF\node_modules\express\lib\router\index.js:321:12)
at next (d:\PMF\node_modules\express\lib\router\index.js:261:10)
at jsonParser (d:\PMF\node_modules\body-parser\lib\types\json.js:96:40)
at Layer.handle [as handle_request] (d:\PMF\node_modules\express\lib\router\layer.js:82:5)
at trim_prefix (d:\PMF\node_modules\express\lib\router\index.js:302:13)
at d:\PMF\node_modules\express\lib\router\index.js:270:7
at Function.proto.process_params (d:\PMF\node_modules\express\lib\router\index.js:321:12)
at next (d:\PMF\node_modules\express\lib\router\index.js:261:10)
at urlencodedParser (d:\PMF\node_modules\body-parser\lib\types\urlencoded.js:84:40)
at Layer.handle [as handle_request] (d:\PMF\node_modules\express\lib\router\layer.js:82:5)
at trim_prefix (d:\PMF\node_modules\express\lib\router\index.js:302:13)
at d:\PMF\node_modules\express\lib\router\index.js:270:7
at Function.proto.process_params (d:\PMF\node_modules\express\lib\router\index.js:321:12)