Node.js Sails.js/Waterline-Create不是模型上的函数
我对Node.js和Sails.js框架都是新手。我正试图用这个框架构建一个网站/应用程序,但在让模型部分按预期工作时遇到了困难。我已经看了很多文档,但是仍然不能执行这个基本任务。我正在使用PostgreSQL适配器 堆栈如下所示:Node.js Sails.js/Waterline-Create不是模型上的函数,node.js,sails.js,waterline,Node.js,Sails.js,Waterline,我对Node.js和Sails.js框架都是新手。我正试图用这个框架构建一个网站/应用程序,但在让模型部分按预期工作时遇到了困难。我已经看了很多文档,但是仍然不能执行这个基本任务。我正在使用PostgreSQL适配器 堆栈如下所示: TypeError: Fragrance.create is not a function\n at Object.module.exports.index (/home/kelly/workspace/Hawthorne-Acres/api/controll
TypeError: Fragrance.create is not a function\n at Object.module.exports.index (/home/kelly/workspace/Hawthorne-Acres/api/controllers/HomeController.js:16:19)\n at wrapper (/usr/local/lib/node_modules/sails/node_modules/@sailshq/lodash/lib/index.js:3250:19)\n at routeTargetFnWrapper (/usr/local/lib/node_modules/sails/lib/router/bind.js:181:5)\n at callbacks (/usr/local/lib/node_modules/sails/node_modules/@sailshq/express/lib/router/index.js:164:37)\n at param (/usr/local/lib/node_modules/sails/node_modules/@sailshq/express/lib/router/index.js:138:11)\n at param (/usr/local/lib/node_modules/sails/node_modules/@sailshq/express/lib/router/index.js:135:11)\n at pass (/usr/local/lib/node_modules/sails/node_modules/@sailshq/express/lib/router/index.js:145:5)\n at nextRoute (/usr/local/lib/node_modules/sails/node_modules/@sailshq/express/lib/router/index.js:100:7)\n at callbacks (/usr/local/lib/node_modules/sails/node_modules/@sailshq/express/lib/router/index.js:167:11)\n at alwaysAllow (/usr/local/lib/node_modules/sails/lib/hooks/policies/index.js:224:11)\n at routeTargetFnWrapper (/usr/local/lib/node_modules/sails/lib/router/bind.js:181:5)\n at callbacks (/usr/local/lib/node_modules/sails/node_modules/@sailshq/express/lib/router/index.js:164:37)\n at param (/usr/local/lib/node_modules/sails/node_modules/@sailshq/express/lib/router/index.js:138:11)\n at param (/usr/local/lib/node_modules/sails/node_modules/@sailshq/express/lib/router/index.js:135:11)\n at pass (/usr/local/lib/node_modules/sails/node_modules/@sailshq/express/lib/router/index.js:145:5)\n at nextRoute (/usr/local/lib/node_modules/sails/node_modules/@sailshq/express/lib/router/index.js:100:7)\n at callbacks (/usr/local/lib/node_modules/sails/node_modules/@sailshq/express/lib/router/index.js:167:11)\n at module.exports (/usr/local/lib/node_modules/sails/lib/hooks/cors/clear-headers.js:14:3)\n at routeTargetFnWrapper (/usr/local/lib/node_modules/sails/lib/router/bind.js:181:5)\n at callbacks (/usr/local/lib/node_modules/sails/node_modules/@sailshq/express/lib/router/index.js:164:37)\n at param (/usr/local/lib/node_modules/sails/node_modules/@sailshq/express/lib/router/index.js:138:11)\n at pass (/usr/local/lib/node_modules/sails/node_modules/@sailshq/express/lib/router/index.js:145:5)"
flanger.js(位于api/models文件夹中):
调用函数的控制器
/**
* HomeController
*
* @description :: Server-side logic for managing Homes
* @help :: See http://sailsjs.org/#!/documentation/concepts/Controllers
*/
var Fragrance = require("../models/Fragrance");
module.exports = {
/**
* `HomeController.Index()`
*/
index: function(req, res) {
Fragrance.create({ fragranceName: 'Vanilla' }).exec(function(err, rec) {
console.log(rec.id);
});
return res.render("index", { title: "Welcome" });
},
/**
* `HomeController.About()`
*/
about: function(req, res) {
console.log("About place");
return res.render("about", { title: "About" });
},
/**
* `HomeController.Contact()`
*/
contact: function(req, res) {
return res.render("contact", { title: "Contact" });
}
};
这可能是显而易见的,但我自己已经努力想办法解决,但没有成功。因此,任何帮助都将不胜感激
谢谢。在
model
文件夹中的型号在全球范围内都可用。您可以禁用config/globals.js
中的功能。所以你可以放弃
var-flanger=require(“../models/flanger”)代码>
然后,您可以通过以下方式创建记录:
香水。创建
方法
或
sails.models.flanger.create
method(注意模型名称是小写的。)
就我个人而言,我更喜欢第二种模式,并关闭模型的全球可用性。在model
文件夹中的模型是全球可用的。您可以禁用config/globals.js
中的功能。所以你可以放弃
var-flanger=require(“../models/flanger”)代码>
然后,您可以通过以下方式创建记录:
香水。创建
方法
或
sails.models.flanger.create
method(注意模型名称是小写的。)
就个人而言,我更喜欢第二种模式,并关闭全球模型的可用性。非常感谢您的回答和基本解释;它现在正在工作。非常感谢您的回答和潜在的解释;它现在正在工作。
/**
* HomeController
*
* @description :: Server-side logic for managing Homes
* @help :: See http://sailsjs.org/#!/documentation/concepts/Controllers
*/
var Fragrance = require("../models/Fragrance");
module.exports = {
/**
* `HomeController.Index()`
*/
index: function(req, res) {
Fragrance.create({ fragranceName: 'Vanilla' }).exec(function(err, rec) {
console.log(rec.id);
});
return res.render("index", { title: "Welcome" });
},
/**
* `HomeController.About()`
*/
about: function(req, res) {
console.log("About place");
return res.render("about", { title: "About" });
},
/**
* `HomeController.Contact()`
*/
contact: function(req, res) {
return res.render("contact", { title: "Contact" });
}
};