10

This might be a very simple question but I don't find anything about it in the Waterline docs.

How is it possible to get an instance of a Waterline model without immediately saving it.

Model.create(data); // already written to database

I am looking for something like

var user = User.new(data); // new instance, not persistent so far
user.doSomething(withThis); // call method on instance
user.save(); // Now write it to database

Thanks

Scimonster
  • 32,893
  • 9
  • 77
  • 89
Ole Spaarmann
  • 15,845
  • 27
  • 98
  • 160
  • Some of these might be what you're looking for. http://sailsjs.org/#!/documentation/concepts/ORM/Lifecyclecallbacks.html – Fissio Jun 18 '15 at 22:50
  • I don't think this is exposed in the public interface, it *may* be possible to do it resorting to private methods... – Dário Jun 19 '15 at 09:46
  • 1
    I think I am mainly looking for it because I am used to it coming from Ruby on Rails. In the end there is no real need to create an instance without writing it to the db. You might want to do something with the user input (hash passwords, validate it, create additional data, etc) before writing it, but validation / sanitation / data manipulation can be achieved using hooks. For anyone with the same question: https://github.com/balderdashy/waterline-docs/blob/master/models/lifecycle-callbacks.md – Ole Spaarmann Jun 19 '15 at 13:02
  • Possible duplicate of [How to create a new instance of a model in sailjs?](https://stackoverflow.com/questions/23559184/how-to-create-a-new-instance-of-a-model-in-sailjs) – Robin Sep 03 '17 at 21:04

1 Answers1

3

Looks like you can utilize basic javascript instantiation. Check out this issue not sure if it has been fixed but you can follow the crumbs from there.

https://github.com/balderdashy/waterline/issues/763

Brad Decker
  • 746
  • 8
  • 20