当我从客户端应用程序运行云代码功能时出现错误:
[Error]: TypeError: Cannot call method 'getUsers' of undefined
at main.js:26:20
at e (Parse.js:3:8736)
at Parse.js:3:8185
at Array.forEach (native)
at Object.x.each.x.forEach [as _arrayEach] (Parse.js:1:661)
at c.extend.resolve (Parse.js:3:8136)
at null.<anonymous> (Parse.js:3:8815)
at e (Parse.js:3:8736)
at Parse.js:3:9489
at g (Parse.js:3:9226) (Code: 141, Version: 1.7.5)
在这个函数中,我想通过相互添加角色来更改两个用户ACL。
Parse.Cloud.define("addFriend", function(request, response) {
var userToFriend = new Parse.User();
userToFriend.id = request.params.friendId;
var roleName = "friendsOf_" + request.user.id;
var roleQuery = new Parse.Query("_Role");
var friendRoleName = "friendsOf_" + userToFriend.id;
var friendQuery = new Parse.Query("_Role");
roleQuery.equalTo("name", roleName);
friendQuery.equalTo("name", friendRoleName);
roleQuery.first().then(function(role) {
role.getUsers().add(userToFriend);
return role.save();
})
.then(function() {
friendQuery.first().then(function(friendRole) {
//Next line gives the error
friendRole.getUsers().add(request.user);
return friendRole.save();
}).then(function() {
response.success("Success!");
});
});
});