0
votes

I am doing a query and I am checking to see if the value in the column "Parent", which is a pointer, is equal to a string, newLogObjectId. I obviously cannot do this since a pointer and a string are a different value type, (returns nil). When I look at the data in Parse, I notice that in the Parent column, the objectId is listed, but within a button, which when clicked, load the NewLog class.
How do I change "Parent" be the objectId in the Pointer in the code "query1.whereKey("Parent", equalTo:newLogObjectId)"? Something like "Parent.objectId"

    //ObjectId of row of Marker Selected, a string, for example, "MCeKMyxRIt"
    let newLogObjectId = objectIdArray[markerIndex]

    //Query ComparablePhotos class
    let query1 = PFQuery(className: "ComparablePhotos")

    //Grab all rows of Parent, equal to newLogObjectId ex: "MCeKMyxRIt"
    //Issue: "Parent" is a pointer, not a String.  Parent has an objectId
    query1.whereKey("Parent", equalTo:newLogObjectId)

    //Get result as an object
    viewRecordObject = query1.findObjects() as! [PFObject]

enter image description here

2
is query1.whereKey("Parent", equalTo:newLog.ObjectId) not working? typically you access username,objectId or whatever column your object is in by .objectId, .username Etc.... Or... query1.Parent.query.findobjectsInBackgroundwithBlock { - Steve DeRienzo
I would query the NewLog class whereKey("objectId", containedIn:objectIdArray) to get all PFObjects with the associated object IDs. Have this query fetch the Parent field, then iterate through your objects to get each Parent. - Connor Neville
No steve, it is not working. I believe if it was Android it would work that way. - Josh O'Connor
And Connor, how do I have the query fetch the Parent field? is there a fetch method - Josh O'Connor

2 Answers

1
votes

In my experience, when it comes to images pictures or big data it is better to use the findObjectsInBackgroundWithBlock method

   var query = PFQuery(className:"")
findObjectsInBackgroundWithBlock {
  (objects: [AnyObject]?, error: NSError?) -> Void in {
     if error == nil{
      // do whatever you want 
       if let data = objects as![PFObject]{
       // now you could just append your array with data
       // something like self.arrayofObjects.append(data)
        }
       }
  }

method because it let you check error and also make easier to add those objects to your array.

0
votes

If you only have an objectId, create a new ParseObject, set its objectId to newLogObjectId, and then use that newly created object (which is a pointer), in your query.

var myNewLog = PFObject(className: "NewLog")
myPointer.objectId = newLogObjectId
query1.whereKey("Parent", myNewLog)