The examples shown here (https://parse.com/docs/relations_guide#onetomany-pointers) is in iOS and Android.
Is it possible to create a Pointer data store with PHP SDK?
The examples shown here (https://parse.com/docs/relations_guide#onetomany-pointers) is in iOS and Android.
Is it possible to create a Pointer data store with PHP SDK?
I just ran into the same issue trying to make a many-to-many relation and after some trial and error I got it working by doing:
$obj = new ParseObject("ObjectClassName");
$obj->setAssociativeArray("relationFieldName", array('__type' => 'Pointer', 'className' => 'relationClassName', 'objectId' => 'relationObjId'));
For example, if you want to relate a Book with a User via the Book's authors key, ObjectClassName would be Book, relationFieldName would be authors and relationClassName would be _User (remember Parse's special classes are prefixed with an underscore).
Let me know if this works for you too! It's a bit frustrating that I couldn't find anything about this on Parse's PHP documentation on relations. I had the same issue in JS before but at least this question helped me right away.
I had the same issue. There is a function in the SDK specifically for this that is more concise.
In \Parse\ParseOject:
$pointer = ParseObject::create('className', $id, true);
I found it in ParseObject.php :
/**
* Static method which returns a new Parse Object for a given class
* Optionally creates a pointer object if the objectId is provided.
*
* @param string $className Class Name for data on Parse.
* @param string $objectId Unique identifier for existing object.
* @param bool $isPointer If the object is a pointer.
*
* @return ParseObject
*/
public static function create($className, $objectId = null, $isPointer = false)
It sounds like you are trying to create a 1-many relationship. You can do this using ParseObject::getRelation, which will return an existing relation, or, create a new one (you can check out the definition here).
$obj = new ParseObject("ObjectClassName");
// get a relation (new or existing)
$relation = $obj->getRelation('myObjects');
// add objects to this relation
$relation->add([$myObject1, $myObject2, $myObject3]);
// save my object & my relation, with the new objects in it
$obj->save();
If you're trying to do many-many relations you'll want to create a Join table (technically a join 'class', like MyParseJoinClass) instead. If I misunderstood, and you're trying to perform a 1-1, you can always set an object as a property to automatically create a pointer
$obj->set('myPointer', $myPointedObject);
Internally you can use $obj->_toPointer to get an array composing a pointer referencing an object, but I would recommend you utilize the supported relation & pointer types in ParseObject instead, much easier to manage.