I'm new to using node-orm2 and am getting caught by the following issue;
我是使用node-orm2的新手,我遇到了以下问题;
TypeError: Object [object Object] has no method 'save'
Full stack trace http://pastebin.com/cb9Lt9pB
完整堆栈跟踪http://pastebin.com/cb9Lt9pB
This error is coming from within a Model method, definition below;
此错误来自Model方法,定义如下;
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
模型定义的完整代码在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).
据我所知,实例没有使用文档(https://node-orm.readthedocs.org/en/latest/ref/instance.html)中概述的save方法返回。
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.
如果我在用户对象上执行console.log,你可以清楚地看到它除了getter和setter之外没有任何方法。
[ { 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.
如果我使用不正确,任何人都可以提供任何见解吗?或任何指针,以帮助我理解为什么save方法不在实例上。
For reference I'm using the latest version of node-orm2 ("orm": "*") with mysql.
作为参考,我使用最新版本的node-orm2(“orm”:“*”)和mysql。
1 个解决方案
#1
5
Even if you limit the number of results to 1, node-orm2
will still pass an array of results:
即使将结果数限制为1,node-orm2仍会传递一组结果:
this.find({uid: uid}, 1, function(err, users) {
if (! err && users.length) {
var user = users[0]; // user.save() should work now
...
}
});
#1
5
Even if you limit the number of results to 1, node-orm2
will still pass an array of results:
即使将结果数限制为1,node-orm2仍会传递一组结果:
this.find({uid: uid}, 1, function(err, users) {
if (! err && users.length) {
var user = users[0]; // user.save() should work now
...
}
});