Parse.com - 保存新PFObject时出错101

时间:2013-10-22 18:30:07

标签: ios parse-platform

我正在创建一个新的PFObject,在其上设置一些对象,然后保存它:

// Add a new 'madeTitle' Activity Object
PFObject* madeTitleActivity = [PFObject objectWithClassName:kPAPActivityClassKey];
[madeTitleActivity setObject:aComment forKey:kWSActivityCommentKey];
[madeTitleActivity setObject:self.photo forKey:kPAPActivityPhotoKey];
[madeTitleActivity setObject:[PFUser currentUser] forKey:kPAPActivityFromUserKey];
[madeTitleActivity setObject:[aComment objectForKey:kWSCommentsFromUserKey] forKey:kPAPActivityToUserKey];
[madeTitleActivity setObject:kPAPActivityTypeMadeTitle forKey:kPAPActivityTypeKey];

// ACL's
PFACL *ACL = [PFACL ACLWithUser:[PFUser currentUser]];
[ACL setPublicReadAccess:YES];
[ACL setWriteAccess:YES forUser:[PFUser currentUser]];
madeTitleActivity.ACL = ACL;


[madeTitleActivity saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

    if (succeeded) {
        // ...
    }
    else {
        NSLog(@"madeTitleActivity saveInBackgroundWithBlock -- error = %@", error);
    }
}];

但我收到以下错误:

2013-10-22 10:55:12.546 WSPhoto[2064:7b4b] Error: object not found for update (Code: 101, Version: 1.2.6)
2013-10-22 10:55:12.552 WSPhoto[2064:707] madeTitleActivity saveInBackgroundWithBlock -- error = Error Domain=Parse Code=101 "The operation couldn’t be completed. (Parse error 101.)" UserInfo=0x8966c0 {code=101, error=object not found for update}

我以前处理过这个错误,但它一直在更新对象并遇到ACL问题。创建和保存新对象时,我没有此错误代码。

我已经检查了我正在设置的所有对象,并且它们都返回了有效对象。

我还成功保存了一些其他的Activity对象,从我可以看出的代码看起来完全一样。


编辑:扩展代码,包括makeTitleActivity代码嵌套在

中的CloudCode函数调用
 [PFCloud callFunctionInBackground:@"setCommentIsTitle"
                   withParameters:@{@"userID":[[PFUser currentUser] objectId],
                     @"objectId":[aComment objectId],
                     @"photoObjectId":[self.photo objectId],
                     @"previousCommentObjectId":[previousTitleComment objectId],
                     @"isTitle":[NSNumber numberWithBool:YES],
                     @"previousCommentObjectIsTitle":[NSNumber numberWithBool:NO]}
                                block:^(NSMutableDictionary *results , NSError *error) {

    if (!error) {
        // Add a new 'madeTitle' Activity Object
        PFObject* madeTitleActivity = [PFObject objectWithClassName:kPAPActivityClassKey];
        [madeTitleActivity setObject:aComment forKey:kWSActivityCommentKey];
        [madeTitleActivity setObject:self.photo forKey:kPAPActivityPhotoKey];
        [madeTitleActivity setObject:[PFUser currentUser] forKey:kPAPActivityFromUserKey];
        [madeTitleActivity setObject:[aComment objectForKey:kWSCommentsFromUserKey] forKey:kPAPActivityToUserKey];
        [madeTitleActivity setObject:kPAPActivityTypeMadeTitle forKey:kPAPActivityTypeKey];

        // ACL's
        PFACL *madeTitleACL = [PFACL ACLWithUser:[PFUser currentUser]];
        [madeTitleACL setPublicReadAccess:YES];
        [madeTitleACL setWriteAccess:YES forUser:[PFUser currentUser]];
        madeTitleActivity.ACL = madeTitleACL;

        [madeTitleActivity saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

            NSLog(@"madeTitleActivity saveInBackgroundWithBlock -- called");

            if (succeeded) {
               // ..
            }
            else {
                NSLog(@"madeTitleActivity saveInBackgroundWithBlock -- error = %@", error);
            }
        }];
    }

    else {
        NSLog(@"etCommentIsTitle PFCloud  -- error = %@", error);
    }
}];

3 个答案:

答案 0 :(得分:1)

此:

  

错误:找不到更新的对象

表示您正在尝试保存与尚未保存的其他对象关系的对象。你不能这样做,因为它不存在。

您需要找出其他对象,并确保首先保存它。


请注意,您可以使用其中一种saveAll...方法批量保存大量新对象,并避免此类问题并获得一些效率提升。

答案 1 :(得分:1)

另外提醒您在尝试保存新对象时不要尝试设置ObjectId。这通常不是问题,除非你不小心吹走你的数据库并尝试将其重新启动。

答案 2 :(得分:0)

它与ACL有关,请在仪表板上查看数据栏“ACL”

写入应该锁定特定的用户ID。您需要从仪表板更改它以更新其权限

{"*":{"write":true,"read":true}}

您可以在this

中查看我的回复的详细信息