本文介绍了如何在sailjs中创建模型的新实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从模型创建一个未持久化的新实例,填充一些属性并将其作为来自控制器操作的 JSON 响应发送回来.在 rails 中,使用 Model.new 获取模型的新实例非常简单,但是如何使用 waterline>sails.js?

I want to create a not persisted new instance from a model, populate some attributes and send it back as a JSON response from a controller action. In rails it's pretty simple to get a new instance of a model with Model.new, but how can I do that with waterline or sails.js?

如果您熟悉 Rails:

If you are familiar with rails:

  • Model.new -> 创建模型的新实例.如何在 Sails.JS 中执行此操作?
  • Model.create -> 创建一个模型的新实例,它(已经)持久化了.
  • Model.new -> Creates a new instance of a model. How can I do this in Sails.JS?
  • Model.create -> Creates a new instance of a model, which is (already) persisted.

我已经查看了文档,但找不到任何相关信息.

I've already checked the documentation, but I couldn't find anything about this.

推荐答案

遗憾的是,Waterline 目前不支持此功能.幸运的是,OSS 社区随时为您提供帮助.

Sadly, this isn't something that's currently supported by Waterline. Luckily, the OSS community is here to help.

检查这个小的 NPM 包,因为它看起来可以满足您的需求.

Check this little NPM package out, as it looks like it will take care of exactly what you need.

https://www.npmjs.com/package/sails-model-new

这篇关于如何在sailjs中创建模型的新实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 07:37