PFUser关系 - 解析云

时间:2014-11-01 19:23:21

标签: ios parse-platform

我正在尝试在User表的Deal关系中获取对象,以便我可以更改该特定引用的值。我正在尝试使用PFCloud执行此操作,因为这涉及在不登录的情况下更改用户的属性/关系。

Parse.Cloud.define("redeemDeal", function(request, response) {
var query = new Parse.Query(Parse.User);
query.equalTo("objectId", request.params.userObjectId);
query.find({
    useMasterKey: true
}).then(function(user) {
  //Found the right user.
  //This is where the JS fails. Cant find the relation
    var dealRelation = user.relation("deals");
    var dealquery = dealRelation.query();
    dealquery.equalTo("objectId", request.params.dealObjectId);
    //trying to find the deal from the relation
    dealquery.find().then(function(deal) {
            deal.setIsRedeemed(true);
            dealRelation.add(deal);
            //Adding that deal back to the relation with redeemed as yes.
            dealRelation.save().then(function(object) {
                    response.success(dealRelation);
                },
                function(error) {
                    response.error(error);
                }
            );
        },
        function(error) {

        });
});

});  我收到此错误。有人可以建议。感谢

TestApp[72316:2635281] Error: TypeError: Object [object Object] has no method 'relation'
at main.js:12:33
at e (Parse.js:2:6486)
at Parse.js:2:5935
at Array.forEach (native)
at Object.x.each.x.forEach [as _arrayEach] (Parse.js:1:664)
at c.extend.resolve (Parse.js:2:5886)
at null.<anonymous> (Parse.js:2:6565)
at e (Parse.js:2:6486)
at Parse.js:2:7239
at g (Parse.js:2:6976) (Code: 141, Version: 1.2.18)

1 个答案:

答案 0 :(得分:1)

我假设数据库的Deals列中的数据类型是指针。在对用户的初始查询中,如果要包含存储在该指针中的对象,则应编写:

var query = new Parse.Query(Parse.User);
query.equalTo("objectId", request.params.userObjectId);
query.include("Deals");

当您的查询成功返回时,它将包含带有用户对象的Deals对象,并使您不必运行另一个查询来获得交易。您还可以在第一个查询的回调中console.log(JSON.stringify(user));查看实际返回的内容,以帮助更好地诊断导致错误的原因。