jugglingdb icon indicating copy to clipboard operation
jugglingdb copied to clipboard

TypeError: Object [Model User] has no method 'isValid'

Open heartforit opened this issue 11 years ago • 2 comments

TypeError: Object [Model User] has no method 'isValid'

Please fix this.

This code does not work User.isValid(function(valid) { if (! valid) { console.log('invalid', user.errors); } else { console.log('valid'); } });

and this one too:

User.create({name: "as", "age": "++"}, function(err, user) { if(user.errors){ res.send({validationErrors:user.errors}); } else { res.send(user); } });

What is wrong?

heartforit avatar Aug 02 '13 13:08 heartforit

You are confusing an instance method with a class method. user.isValid() is an instance method. Typically, capitalization is used to denote a class.

var User = schema.models.User;
var user = User.create(); // user is an instance of User class

Class methods:

User.create
User.validatesPresenceOf
User.validatesUniquenessOf
...

Instance methods:

user.isValid
user.save
user.destroy
...

alexmingoia avatar Aug 02 '13 15:08 alexmingoia

Thank you so much.

This issue could be closed!

heartforit avatar Aug 02 '13 16:08 heartforit