简体   繁体   English

将自定义对象作为指针插入Parse中。 [错误]:objectId是无效的字段名称

[英]Inserting Custom object as pointer in Parse. [Error]: objectId is an invalid field name

I have a Product object that I get form database in Parse. 我有一个Product对象,可以在Parse中获取表单数据库。 So I am trying to create UserFavourites object, that has user_id and the Product object, that already in Parse database. 因此,我试图创建UserFavourites对象,该对象具有user_id和Product对象,该对象已经存在于Parse数据库中。

This is the code: 这是代码:

PFObject *product = [PFObject objectWithClassName:@"Product"];
    product[@"objectId"] = @"8gFcLQ3oZo";
    userFavourite[@"product"] = product;
    userFavourite[@"user"] = [[PFUser currentUser] objectId];
    [userFavourite saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (succeeded) {
            // The object has been saved.
        } else {
            // There was a problem, check error.description
        }
    }];

I took those values that I assign, form db. 我采用了我分配的值,即db。 This is just for testing. 这仅用于测试。 However, I get the error: 但是,我得到了错误:

[Error]: objectId is an invalid field name (Code: 105, Version: 1.7.1)

This is because of I am setting objectId. 这是因为我正在设置objectId。 But when I remove this like, for setting objectId, the Product object gets inserted to Product table as new object (dublicating exisitng one, but with new objectId). 但是,当我删除此类对象时,为了设置objectId,会将Product对象作为新对象插入到Product表中(复制现有对象,但使用新的objectId)。 I thought that I need to specify objectId, so that it would not get inserted as new object. 我以为我需要指定objectId,以便它不会作为新对象插入。 So, what is the right way to achieve my goal? 那么,实现我的目标的正确方法是什么?

尝试这样设置objectId

 [product setObjectId:@"myId"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM