How to create a new instance of a model in sailjs?

亡梦爱人 提交于 2019-12-11 02:24:01

问题


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?

If you are familiar with rails:

  • 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.


回答1:


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

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



来源:https://stackoverflow.com/questions/23559184/how-to-create-a-new-instance-of-a-model-in-sailjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!