I'm new to using node-orm2 and am getting caught by the following issue;
TypeError: Object [object Object] has no method 'save'
Full stack trace http://pastebin.com/cb9Lt9pB
This error is coming from within a Model method, definition below;
User.findOrCreate = function (providerName, token, tokenSecret, uid, profile, done) {
this.find({uid: uid}, 1, function(err, user) {
if (user) {
user.displayName = profile.displayName;
user.profileImage = profile._json.profile_image_url;
user.save(function(err){
return done(err, user, false);
});
} else {
....
The full code for the model definition is here http://pastebin.com/7Bv8XG36
From what I can tell the instance isn't being returned with a save method as outlined in the documentation (https://node-orm.readthedocs.org/en/latest/ref/instance.html).
If I perform a console.log on the user object you can clearly see it doesn't have any methods other than getters and setters.
[ { id: [Getter/Setter],
uid: [Getter/Setter],
username: [Getter/Setter],
displayName: [Getter/Setter],
token: [Getter/Setter],
tokenSecret: [Getter/Setter],
profileImage: [Getter/Setter] } ]
Can anyone provide any insight to if I'm using this incorrectly? Or any pointers to help me understand why the save method isn't on the instance.
For reference I'm using the latest version of node-orm2 ("orm": "*") with mysql.
Even if you limit the number of results to 1, node-orm2
will still pass an array of results:
this.find({uid: uid}, 1, function(err, users) {
if (! err && users.length) {
var user = users[0]; // user.save() should work now
...
}
});