Skip to content
This repository has been archived by the owner on Feb 25, 2018. It is now read-only.

add/remove relations #23

Closed
jobrienski opened this issue Jul 25, 2012 · 2 comments
Closed

add/remove relations #23

jobrienski opened this issue Jul 25, 2012 · 2 comments

Comments

@jobrienski
Copy link

I added a function called relate to add or remove a relation to your code. Not that good at github, so here is the function:

/**
 *
 * Used to add or remove a relation to a parse.com object
 *
 * @param array $args - argument hash:
 *
 * className: string of className
 * objectId: the objectId of the object you want to update
 * add: boolean
 * columnName: the column name of the relation
 * relationClassName: the classname of the relation you want to add
 * relationObjectId: the objectId of the related object
 */
       public function relate($args){
                $params = array(
                        'url' => $args['className'].'/'.$args['objectId'],
                        'method' => 'PUT'
                );

                $objects = array(
                        "__type" => "Pointer",
                        "className" => $args['relationClassName'],
                        "objectId" => $args['relationObjectId']
                );

                $relation = array(
                        $args['columnName'] => array(
                                                "__op" =>
                                                ($args['add'] ? "Add" : "Remove") . "Relation",
                                                "objects" => array($objects)
                                        )
                );


                $params['payload'] = $relation;

                $return = $this->request($params);

                return $this->checkResponse($return,'200');
        }
@jobrienski
Copy link
Author

In the interest of full disclosure, I haven't thoroughly tested this. "Add" seems to work, haven't tested "Remove" at all.

@andrewscofield
Copy link
Owner

Thanks! I'll put this in the new version, it will have some tests in there.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants