Search code examples
loopbackjsstrongloop

How to instaniate Model object from data in code?


How to instaniate the model object from some data object to run validation with isValid method? Is there constructor method?


Solution

  • You can use the model itself.

    var data = {name: 'a'};
    var obj = new app.models.MyModel(data);
    obj.isValid(function(valid){
      if(valid === false){
        console.log(obj.errors);
      }
    });