【问题标题】:Parse Cloud Code - Why can't I delete a Parse.Role?Parse Cloud Code - 为什么我不能删除 Parse.Role?
【发布时间】:2016-03-12 13:59:28
【问题描述】:

我不知道如何删除云代码中的 Parse.Role。该指南说它们是 Parse.Object 的子类,并且具有所有相同的方法。但是我收到以下错误,为什么我尝试删除一个:

Object [object Object] 没有方法'destroy'

Parse.Cloud.afterDelete("Project", function(request) {

    Parse.Cloud.useMasterKey();

    var query = new Parse.Query(Parse.Role);
    query.equalTo("name", "hasSound_" + request.object.id);

    query.find().then(function(role) {

        if(typeof role === 'undefined') {
            console.log("role is undefined, cannot delete");
        }
        else {
            role.destroy();
        }

    }).then(function(success) {
        console.log("role deleted: hasSound_" + request.object.id);
    }, function(error) {
        console.log("error deleting role");
    });

});

我有一些 console.log 语句验证“名称”是否正确,因此查询应该找到正确的对象。我不确定还能尝试什么。

另外,我的角色是以项目的 ID 命名的。所以每个项目都有一个名为“hasSound_[id of project]”的角色。当我删除一个项目时,我不再需要与之关联的角色。我的意思是我可以将未使用的项目留在数据库中,但这似乎很浪费。

【问题讨论】:

    标签: javascript parse-platform parse-cloud-code


    【解决方案1】:

    find() 由匹配对象的 array 实现。由于您的角色是独一无二的,您可以安全地将find() 更改为first()。或者您可以继续使用find(),但将结果视为一个数组。

    【讨论】:

    • 谢谢你,这样的菜鸟错误。我在其他地方使用first(),这里会用到。
    猜你喜欢
    • 2014-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-25
    相关资源
    最近更新 更多