rihekopo
rihekopo

Reputation: 3350

Why can't add PFObject to PFRelation?

I would like to add a PFObject to a PFUser's PFRelation, but unfortunately it doesn't want to work. I'm getting this error:

[Error]: wrong type of relation.  Expecting: _User, but received: itemClass

Please somebody give me some guidance, because the PFRelation class reference states that the PFRelation's addObject: method uses a PFObject so it must work. Is it possible that I can't add a PFObject to a PFRelation which belongs to the _User class? Thanks!

Here's my implementation:

- (void)addItem:(PFObject *)newItem {

    PFRelation *itemRelation = [[PFUser currentUser] relationForKey:@"items"];
    [itemRelation addObject:newItem];

    [[PFUser currentUser] saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (succeeded){

            NSLog(@"ITEM SAVED");

        } else {

            NSLog(@"Error %@ %@", error, [error userInfo]);

        }
    }];
}

Upvotes: 1

Views: 69

Answers (1)

danh
danh

Reputation: 62686

Since the column is declared as a relation to _User, only a PFUser will suffice as an operand to add to the relation. While PFUser is a subclass of PFObject in the iOS sdk, the only thing that makes sense to place in a relation is a concrete instance of the relation type.

Upvotes: 2

Related Questions