javascript - Waterline .create() 不是函数
问题描述
使用 Sails.js 和 Waterline-ORM 开发一个简单的 REST,现在在 Post-request 上尝试在 orm 中创建一个简单对象时面临Post.create 不是函数问题。
模型:
module.exports = {
attributes: {
title: {
type: "string",
required: true,
},
body: {
type: "string",
required: true,
},
},
};
控制器
createPost: async (req, res) => {
const title = req.body.title;
const body = req.body.body;
try {
let newPost = Post.create({ title: title, body: body }).fetch();
} catch (error) {
console.log(newPost);
}
}
我已经检查了文档和官方 gh-issues,但是没有工作建议,我不明白我在做什么错
解决方案
有时,当编辑器自动加载其他Post文件而不是sails 全局模型时,我会遇到这种情况,即const Post = require('../models/Post');
在控制器文件的顶部。
推荐阅读
- c# - 为什么一个物体在另一个物体下的孩子比例不一样?以及如何将对象缩放为相同大小?
- html - jquery 3.5.1 移动 css 格式未显示在带有 vs 代码的实时服务器预览中
- math - 来自随机数的正态分布样本
- javascript - 刷新网站或在 Safari(iOS 和 macOS)上安装 PWA 后视频不加载
- flutter - Flutter 中带有 Img 的自定义滑块
- python - 无法导入模块“lambda_function”:没有名为 * 的模块
- c++ - 为什么 stoi 会导致错误以及如何在 Makefile 中修复
- sql - 如何将日期四舍五入到最接近的月份,然后在 sql lite 中添加一个月?
- javascript - 如何使用 chrome 扩展名填写 VUE.js 页面表单输入?
- sas - SAS 警告:数据点完全分离。最大似然估计不存在