0

I may be missing something simple but I thought I would ask here since I was unable to find any information on the subject of saving an array of pointers with the parse php sdk.

I have a list of object id's from the Groups Class, and I want to save those object id's as an array of pointers to my Organization class.

  try {
    $query = new ParseQuery("Organization");
    $query->equalTo('objectId', $objectID);
    $results = $query->first($useMasterKey = true);

    $groups = ParseObject::create('Organization', $data, true);
    $groups->set("test1" , $groups);
    $groups->save($useMasterKey = true);

    $results->setArray("groups", $data);
    //$results->setArray("test1", array('__type' => 'Pointer', 'className' => 'Group', 'objectId' => $data[0]));
    //$results->setAssociativeArray("test1", array($groups[0]));
    $results->save($useMasterKey = true);
  } catch (\Exception $e){
     print("An error has occurred with code: " . $e->getMessage());
  }  

$data is an array of object group object ID's

any help would be appreciated.

2
  • See stackoverflow.com/a/31637825/2124535 Commented Aug 15, 2017 at 2:01
  • that doesn't do it.. it tries to create a pointer, when the type is array.. We are able to do this with the iOS client, and the output in the array type column looks like this.. [ { "__type": "Pointer", "className": "Comment", "objectId": "5JbTj2k7hx" }, { "__type": "Pointer", "className": "Comment", "objectId": "oo69vxrQG0" } ] Note this is for another collection but im trying to repo this now with the parse php sdk for groups associated with an org. Commented Aug 15, 2017 at 16:00

1 Answer 1

0

Ok, here is how I ended up doing it if someone else runs into this situation.

Looking over the iOS app that we have that creates similar output in the database this functionality

Comment(withoutDataWithObjectId: aPossibleObjectIdString)

Helps create an array of what looks like Pointers.

[ { "__type": "Pointer", "className": "Group", "objectId": "5JbTj2k7hx" }, { "__type": "Pointer", "className": "Group", "objectId": "oo69vxrQG0" } ]

This was just pasted from the database. It allows the client to pull things in as a pointer somehow..

Honestly I'm not sure this is the best way to do this but what I ended up using.

  // HACK to add pointer type data into array type column.
  // Value is the objectID from the groups collection.
  foreach($data as $value) {
    $groups[] = array(
      "__type" => "Pointer",
      "className" => "Group",
      "objectId" => $value
    ); 
  }

  try {
    $query = new ParseQuery("Organization");
    $query->equalTo('objectId', $objectID);
    $results = $query->first($useMasterKey = true);
    $results->setArray("groupPointer", $groups);  // actual data that was generated ..   
    $results->setArray("groups", $data);
    $results->save($useMasterKey = true);
  } catch (\Exception $e){
     print("An error has occurred with code: " . $e->getMessage());
  }  
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.