- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试在保存项目时进行验证。这是我的简化模型:
Sample.add({
isPublished: { type: Types.Boolean, default: false },
thumbnailImage: { type: Types.CloudinaryImage, folder: 'samples/thumbnails' },
});
Sample.schema.pre('validate', function(next) {
if (this.isPublished && !(_.isEmpty(this.thumbnailImage.image))) {
next('Thumbnail Image is required when publishing a sample');
}
else {
next();
}
});
如果 Sample
模型将 isPublished
设置为 true
但 thumbnailImage
没有已设置。当我 console.log()
值时,我分别看到 true
和 false
,但 Keystone Admin 中没有出现验证错误。
我浏览了 Github 上的 Keystone 示例应用程序,Mongoose 文档有很多示例,但我还没有看到任何处理多个文档路径的示例。
示例位于:mongoose custom validation using 2 fields (目前有 12 票)对我也不起作用。
我做错了什么?我正在使用 Mongoose 3.8.35。
最佳答案
您不应该 !
否定验证条件的第二部分,因为当它不为空时您正在标记验证错误。
所以改成:
Sample.schema.pre('validate', function(next) {
if (this.isPublished && _.isEmpty(this.thumbnailImage.image)) {
next(Error('Thumbnail Image is required when publishing a sample'));
}
else {
next();
}
});
请注意,您还需要将错误字符串包装在 Error
中调用 next
报告验证失败时的对象。
关于node.js - 在 Keystone.js 中验证相互依赖的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33084927/
我有一个(我希望)关于 Keystone 中授权的快速问题:“用户”对象似乎是框架中的核心依赖项。我想完全避开它,但似乎没有办法在没有它的情况下使应用程序正常运行。 我在这里运行了一个基本的绕过: k
我像这样创建一个 KeyStone 实例: import cherrypy from keystoneauth1 import session as session from keystonec
我使用了 Select 字段,但使用手动选择选项创建。我有类别列表,我想创建另一个包含类别字段的列表。我想通过将所有类别提取到我的 Select 字段来选择我想要的类别。我怎样才能做到这一点?提前致谢
我已根据 ubuntu 12.04 上的“openstack-install-guide-apt-havana.pdf”安装了 keystone,但无法创建新租户: robbie@robbie-Con
我在将 Stemcell 上传到 Bosh Director 时遇到连接超时错误。我正在使用 bosh cli v2。以下是我的错误日志。 > bosh -e sdp-bosh-env upload-
我在 Linux 上安装 keystone.js 时遇到问题。不太确定到底是什么问题,因为我是 Linux 的新手。下面是我尝试使用 npm install -g generator-keystone
我正在尝试构建一个与 keystone 演示中使用的非常相似的联系表单,但我遇到了障碍,在尝试保存到数据库时,出现以下错误 { message: 'Validation failed',
我设置了 keystone v3,然后创建了一个域 dom1,一个用户 adm1 并授予该用户管理员角色。使用域范围验证此用户。然后在dom1下创建一个项目。我试图列出具有创建项目的相同标记的项目。我
我是 keystone.js 的新手。我有这样格式的数据: { _id: 5551823e7771fc3f0decb03e, slug: 'marketing-manager',
我试图了解/查找 KeystoneJS 如何将 LESS 文件编译为 .css 以实现源映射插件或类似的东西。因为它真的很难调试。有什么想法吗? 最佳答案 如果你设置了 gulp 就可以做到。您可以选
我有一个 azure web 应用程序,并将我的 keystone 应用程序从 github 部署到 azure。不幸的是我最终遇到了 500 错误: Tue May 23 2017 19:36:05
我在多节点环境中安装了 swift-proxy 和 keystone。 当我尝试 curl 获取 token 时,keystone 成功返回 token curl -d '{"auth":{"pass
我在 keystone 中创建了 2 个模型。一是 CD_Book,二是音乐家。当我打开 CD_Book View 时,我尝试连接这两个集合。我想显示来自 cd 的音乐家,所以我创建了这个查询:
我是 keystone.js 的新手,我想弄清楚登录页面的位置。我在 keystone.js 文件中找不到登录页面。谁能告诉我如何在 .hbs 文件中获取该登录信息? 最佳答案 KeystoneJS
我正在使用 KeystoneJS 做一个电子商务网站(学习目的)。在我显示所有产品的 View 中,我想添加一个过滤器以按价格对项目进行排序,另一个过滤器仅显示一个品牌的产品。需要两份表格,但我不能只
我需要在我的 Keystone JS 项目上播放视频。我实际上是手动上传视频并通过 html 静态代码添加它,但我需要从管理面板上传它们。我正在查看 Keystone 指南,但只有一种类似文件类型的方
我正在扩展 keystone.js 以支持模型中的多种语言。 原始模型如下所示: Post.add({ title: { type: String, required: true },
我已经在 Ubuntu 12.04 中安装了 OpenStack。 我在执行此命令时收到此错误。 keystone user-list 错误是这样的。 Expecting authentication
我是 Keystone 的新手,但一整天都在尝试查找当前登录的用户名,但我不清楚如何执行此操作。 例如,如果我从 keystone 获取索引 View {{! Welcome
好吧,我对 Keystone JS 还很陌生,我决定将它用作项目的 API 后端。 我已经完成了所有 API 端点/路由,并且它们在我的浏览器中完美运行,但是当尝试远程获取数据时,我不断收到相同的错误
我是一名优秀的程序员,十分优秀!