问题
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