Josh O'Connor
Josh O'Connor

Reputation: 4962

Query row in Parse using Pointer (ios)

I am trying to get a row of data from the class, ComparablePhotos in Parse. However, the only row from ComparablePhotos I want to get, is the row whose pointer, column "Parent", has the same objectId (in NewLog) as a string variable I have, markerObjectId, ex: inI9tJ8x7. I would use the simple query in ComparablePhotos where key "Parent" is equal to markerObjectId, but Parent is a pointer, and not a string.

How do I grab the row from ComparablePhotos whos whose pointer, column "Parent", has the same NewLog objectId as a markerObjectId?  Something along the lines like if the ComparablePhotos row's Parent.objectId == markerObjectId, store that row into a variable?

ComparablePhotos class in Parse. "Parent" column is a pointer. enter image description here

NewLogClass. The pointer points here. enter image description here

Here is my code:

    var newLogObjectsArray: [PFObject] = [PFObject]()

    //newLogObjectId is a string im comparing to, ex: inI9tJ8x7
    newLogObjectId = objectIdArray[markerIndex]

    var picquery = PFQuery(className:"ComparablePhotos")
    picquery.selectKeys(["objectId", "Images", "LocationType", "Parent"])
    picquery.includeKey("Parent.objectId")
    picquery.orderByAscending("createdAt")
    picquery.findObjectsInBackgroundWithBlock { (NewLog, error) -> Void in

        //Here prints are all our rows from the class, ComparablePhotos.
        println("NewLog")

        if let NewLog = NewLog as? [PFObject] {
            for log in NewLog {
                //Here are all our rows from the class, NewLog.
                var ParseNewLogClass: PFObject = (log["Parent"] as? PFObject)!
                self.newLogObjectsArray.append(ParseNewLogClass)
            }

Upvotes: 1

Views: 811

Answers (1)

Wain
Wain

Reputation: 119031

Your current code:

var picquery = PFQuery(className:"ComparablePhotos")
picquery.selectKeys(["objectId", "Images", "LocationType", "Parent"])
picquery.includeKey("Parent.objectId")
picquery.orderByAscending("createdAt")
  • creates a query for ComparablePhotos
  • asks for a limited set of data fields to be returned (selectKeys)
  • asks for an associated object to be included in the response (incorrectly) (includeKey)
  • orders the results

What you actually want is to get the full object details in the response and to filter by a specified parent. To do that you need to create a PFObject for the parent object id details you have (see objectWithoutDataWithClassName:objectId:) and then use whereKey:equalTo:.

var picquery = PFQuery(className:"ComparablePhotos")
picquery.includeKey("Parent")
picquery.whereKey("Parent", equalTo:parentObject)
picquery.orderByAscending("createdAt")

Upvotes: 2

Related Questions